xapian-core  1.4.27
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 std::map;
36 using std::string;
37 using std::swap;
38 
39 class DocumentValueList;
41 
44  friend class ::DocumentValueList;
45  friend class ::ValueStreamDocument;
46  public:
48  typedef map<Xapian::valueno, string> document_values;
49 
51  typedef map<string, OmDocumentTerm> document_terms;
52 
53  protected:
56 
57  private:
58  // Prevent copying
59  Internal(const Internal &);
60  Internal & operator=(const Internal &);
61 
62  bool data_here;
63  mutable bool values_here; // FIXME mutable is a hack
64  mutable bool terms_here;
65  mutable bool positions_modified;
66 
68  string data;
69 
71  mutable document_values values; // FIXME mutable is a hack
72 
74  mutable document_terms terms;
75 
83 
84  protected:
91 
92  private:
93  // Functions for backend to implement
94  virtual string do_get_value(Xapian::valueno /*valueno*/) const { return string(); }
95  virtual void do_get_all_values(map<Xapian::valueno, string> & values_) const {
96  values_.clear();
97  }
98  virtual string do_get_data() const { return string(); }
99 
100  public:
117  string get_value(Xapian::valueno slot) const;
118 
124  void set_all_values(map<Xapian::valueno, string> & values_) {
125  // For efficiency we just swap the old and new value maps.
126  swap(values, values_);
127  values_here = true;
128  }
129 
131  void add_value(Xapian::valueno, const string &);
133  void clear_values();
134  void add_posting(const string &, Xapian::termpos, Xapian::termcount);
135  void add_term(const string &, Xapian::termcount);
136  void remove_posting(const string &, Xapian::termpos, Xapian::termcount);
137  Xapian::termpos remove_postings(const string &,
140  void remove_term(const string &);
141  void clear_terms();
143 
157  string get_data() const;
158 
159  void set_data(const string &);
160 
169  TermList * open_term_list() const;
170 
171  void need_values() const;
172  void need_terms() const;
173 
176  bool data_modified() const {
177  return data_here;
178  }
179 
182  bool values_modified() const {
183  return values_here;
184  }
185 
188  bool terms_modified() const {
189  return terms_here;
190  }
191 
193  bool term_positions_modified() const {
194  return positions_modified;
195  }
196 
198  bool modified() const {
199  return terms_here || values_here || data_here;
200  }
201 
211  Xapian::docid get_docid() const { return did; }
212 
214  string get_description() const;
215 
222  Xapian::docid did_)
223  : database(database_), data_here(false), values_here(false),
224  terms_here(false), positions_modified(false), did(did_) { }
225 
227  : database(), data_here(false), values_here(false),
228  terms_here(false), positions_modified(false), did(0) { }
229 
235  virtual ~Internal();
236 };
237 
238 #endif // OM_HGUARD_DOCUMENT_H
bool term_positions_modified() const
Return true if term positions may have been modified.
Definition: document.h:193
document_values values
The values associated with this document.
Definition: document.h:71
typedefs for Xapian
map< Xapian::valueno, string > document_values
Type to store values in.
Definition: document.h:48
bool values_modified() const
Return true if the values in the document may have been modified.
Definition: document.h:182
Xapian::docid did
The document ID of the document in that database.
Definition: document.h:90
void set_data(const string &)
Definition: omdocument.cc:422
void add_posting(const string &, Xapian::termpos, Xapian::termcount)
Definition: omdocument.cc:473
A document which gets its values from a ValueStreamManager.
TermList * open_term_list() const
Open a term list.
Definition: omdocument.cc:429
Internal(Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database_, Xapian::docid did_)
Constructor.
Definition: document.h:221
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:74
Iteration over values in a document.
A document in the database, possibly plus modifications.
Definition: document.h:43
Abstract base class for termlists.
Definition: termlist.h:39
virtual string do_get_data() const
Definition: document.h:98
virtual void do_get_all_values(map< Xapian::valueno, string > &values_) const
Definition: document.h:95
Xapian::termcount termlist_count() const
Definition: omdocument.cc:593
#define false
Definition: header.h:9
Xapian::valueno values_count() const
Definition: omdocument.cc:625
void remove_posting(const string &, Xapian::termpos, Xapian::termcount)
Definition: omdocument.cc:510
Xapian::termcount termlist_size
The number of distinct terms in terms.
Definition: document.h:82
virtual ~Internal()
Destructor.
Definition: omdocument.cc:683
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
string get_data() const
Get data stored in document.
Definition: omdocument.cc:413
string get_value(Xapian::valueno slot) const
Get value by value number.
Definition: omdocument.cc:400
Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database
The database this document is in.
Definition: document.h:55
bool modified() const
Return true if the document may have been modified.
Definition: document.h:198
void set_all_values(map< Xapian::valueno, string > &values_)
Set all the values.
Definition: document.h:124
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:49
Internal & operator=(const Internal &)
bool data_modified() const
Return true if the data in the document may have been modified.
Definition: document.h:176
Xapian::docid get_docid() const
Get the docid which is associated with this document (if any).
Definition: document.h:211
void remove_term(const string &)
Definition: omdocument.cc:562
virtual string do_get_value(Xapian::valueno) const
Definition: document.h:94
void remove_value(Xapian::valueno)
Definition: omdocument.cc:453
void add_term(const string &, Xapian::termcount)
Definition: omdocument.cc:493
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:188
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:51
void add_value(Xapian::valueno, const string &)
Definition: omdocument.cc:440
Xapian::termpos remove_postings(const string &, Xapian::termpos, Xapian::termpos, Xapian::termcount)
Definition: omdocument.cc:531
string data
The (user defined) data associated with this document.
Definition: document.h:68
string get_description() const
Return a string describing this object.
Definition: omdocument.cc:634