xapian-core  1.4.19
document.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002 Ananova Ltd
6  * Copyright 2003,2004,2005,2007,2008,2009,2010,2011 Olly Betts
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23 
24 #ifndef OM_HGUARD_DOCUMENT_H
25 #define OM_HGUARD_DOCUMENT_H
26 
27 #include "xapian/intrusive_ptr.h"
28 #include <xapian/types.h>
29 #include "api/termlist.h"
30 #include "backends/database.h"
31 #include "api/documentterm.h"
32 #include <map>
33 #include <string>
34 
35 using namespace std;
36 
37 class DocumentValueList;
39 
42  friend class ::DocumentValueList;
43  friend class ::ValueStreamDocument;
44  public:
46  typedef map<Xapian::valueno, string> document_values;
47 
49  typedef map<string, OmDocumentTerm> document_terms;
50 
51  protected:
54 
55  private:
56  // Prevent copying
57  Internal(const Internal &);
58  Internal & operator=(const Internal &);
59 
60  bool data_here;
61  mutable bool values_here; // FIXME mutable is a hack
62  mutable bool terms_here;
63  mutable bool positions_modified;
64 
66  string data;
67 
69  mutable document_values values; // FIXME mutable is a hack
70 
72  mutable document_terms terms;
73 
81 
82  protected:
89 
90  private:
91  // Functions for backend to implement
92  virtual string do_get_value(Xapian::valueno /*valueno*/) const { return string(); }
93  virtual void do_get_all_values(map<Xapian::valueno, string> & values_) const {
94  values_.clear();
95  }
96  virtual string do_get_data() const { return string(); }
97 
98  public:
115  string get_value(Xapian::valueno slot) const;
116 
122  void set_all_values(map<Xapian::valueno, string> & values_) {
123  // For efficiency we just swap the old and new value maps.
124  swap(values, values_);
125  values_here = true;
126  }
127 
128  Xapian::valueno values_count() const;
129  void add_value(Xapian::valueno, const string &);
130  void remove_value(Xapian::valueno);
131  void clear_values();
132  void add_posting(const string &, Xapian::termpos, Xapian::termcount);
133  void add_term(const string &, Xapian::termcount);
134  void remove_posting(const string &, Xapian::termpos, Xapian::termcount);
135  Xapian::termpos remove_postings(const string &,
138  void remove_term(const string &);
139  void clear_terms();
140  Xapian::termcount termlist_count() const;
141 
155  string get_data() const;
156 
157  void set_data(const string &);
158 
167  TermList * open_term_list() const;
168 
169  void need_values() const;
170  void need_terms() const;
171 
174  bool data_modified() const {
175  return data_here;
176  }
177 
180  bool values_modified() const {
181  return values_here;
182  }
183 
186  bool terms_modified() const {
187  return terms_here;
188  }
189 
191  bool term_positions_modified() const {
192  return positions_modified;
193  }
194 
196  bool modified() const {
197  return terms_here || values_here || data_here;
198  }
199 
209  Xapian::docid get_docid() const { return did; }
210 
212  string get_description() const;
213 
220  Xapian::docid did_)
221  : database(database_), data_here(false), values_here(false),
222  terms_here(false), positions_modified(false), did(did_) { }
223 
225  : database(), data_here(false), values_here(false),
226  terms_here(false), positions_modified(false), did(0) { }
227 
233  virtual ~Internal();
234 };
235 
236 #endif // OM_HGUARD_DOCUMENT_H
bool term_positions_modified() const
Return true if term positions may have been modified.
Definition: document.h:191
document_values values
The values associated with this document.
Definition: document.h:69
typedefs for Xapian
map< Xapian::valueno, string > document_values
Type to store values in.
Definition: document.h:46
bool values_modified() const
Return true if the values in the document may have been modified.
Definition: document.h:180
Xapian::docid did
The document ID of the document in that database.
Definition: document.h:88
A document which gets its values from a ValueStreamManager.
Internal(Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database_, Xapian::docid did_)
Constructor.
Definition: document.h:219
internal class representing a term in a modified document
document_terms terms
The terms (and their frequencies and positions) in this document.
Definition: document.h:72
Iteration over values in a document.
A document in the database, possibly plus modifications.
Definition: document.h:41
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
virtual string do_get_data() const
Definition: document.h:96
virtual void do_get_all_values(map< Xapian::valueno, string > &values_) const
Definition: document.h:93
#define false
Definition: header.h:9
Xapian::termcount termlist_size
The number of distinct terms in terms.
Definition: document.h:80
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database
The database this document is in.
Definition: document.h:53
bool modified() const
Return true if the document may have been modified.
Definition: document.h:196
void set_all_values(map< Xapian::valueno, string > &values_)
Set all the values.
Definition: document.h:122
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:49
bool data_modified() const
Return true if the data in the document may have been modified.
Definition: document.h:174
Xapian::docid get_docid() const
Get the docid which is associated with this document (if any).
Definition: document.h:209
virtual string do_get_value(Xapian::valueno) const
Definition: document.h:92
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:83
Abstract base class for termlists.
bool terms_modified() const
Return true if the terms in the document may have been modified.
Definition: document.h:186
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
map< string, OmDocumentTerm > document_terms
Type to store terms in.
Definition: document.h:49
string data
The (user defined) data associated with this document.
Definition: document.h:66