database.h
Go to the documentation of this file.
1 /* database.h: database class declarations
2  *
3  * Copyright 1999,2000,2001 BrightStation PLC
4  * Copyright 2002 Ananova Ltd
5  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009 Olly Betts
6  * Copyright 2006,2008 Lemur Consulting Ltd
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_DATABASE_H
25 #define OM_HGUARD_DATABASE_H
26 
27 #include <string>
28 
29 #include "internaltypes.h"
30 
31 #include <xapian/base.h>
32 #include <xapian/types.h>
33 #include <xapian/database.h>
34 #include <xapian/document.h>
36 #include <xapian/termiterator.h>
37 #include <xapian/valueiterator.h>
38 
39 using namespace std;
40 
41 class LeafPostList;
43 
47 
48 // Used by flint and chert.
49 const int XAPIAN_DB_READONLY = 0;
50 
51 namespace Xapian {
52 
53 struct ReplicationInfo;
54 
58  private:
60  Internal(const Internal &);
61 
63  void operator=(const Internal &);
64 
65  protected:
67  enum {
68  TRANSACTION_UNIMPLEMENTED = -1, // Used by InMemory.
69  TRANSACTION_NONE = 0,
70  TRANSACTION_UNFLUSHED = 1,
71  TRANSACTION_FLUSHED = 2
72  } transaction_state;
73 
74  bool transaction_active() const { return int(transaction_state) > 0; }
75 
77  Internal() : transaction_state(TRANSACTION_NONE) { }
78 
89  void dtor_called();
90 
91  public:
103  virtual ~Internal();
104 
108  virtual void keep_alive();
109 
111  // Database statistics:
112  // ====================
113 
116  virtual Xapian::doccount get_doccount() const = 0;
117 
120  virtual Xapian::docid get_lastdocid() const = 0;
121 
123  virtual totlen_t get_total_length() const = 0;
124 
130  virtual Xapian::doclength get_avlength() const = 0;
131 
142  virtual Xapian::termcount get_doclength(Xapian::docid did) const = 0;
143 
151  virtual Xapian::doccount get_termfreq(const string & tname) const = 0;
152 
161  virtual Xapian::termcount get_collection_freq(const string & tname) const = 0;
162 
173  virtual Xapian::doccount get_value_freq(Xapian::valueno slot) const;
174 
182  virtual std::string get_value_lower_bound(Xapian::valueno slot) const;
183 
191  virtual std::string get_value_upper_bound(Xapian::valueno slot) const;
192 
194  virtual Xapian::termcount get_doclength_lower_bound() const;
195 
197  virtual Xapian::termcount get_doclength_upper_bound() const;
198 
200  virtual Xapian::termcount get_wdf_upper_bound(const std::string & term) const;
201 
206  virtual bool term_exists(const string & tname) const = 0;
207 
210  virtual bool has_positions() const = 0;
211 
213  // Data item access methods:
214  // =========================
215 
230  virtual LeafPostList * open_post_list(const string & tname) const = 0;
231 
241  virtual ValueList * open_value_list(Xapian::valueno slot) const;
242 
253  virtual TermList * open_term_list(Xapian::docid did) const = 0;
254 
264  virtual TermList * open_allterms(const string & prefix) const = 0;
265 
277  virtual PositionList * open_position_list(Xapian::docid did,
278  const string & tname) const = 0;
279 
296  open_document(Xapian::docid did, bool lazy) const = 0;
297 
304  virtual TermList * open_spelling_termlist(const string & word) const;
305 
311  virtual TermList * open_spelling_wordlist() const;
312 
314  virtual Xapian::doccount get_spelling_frequency(const string & word) const;
315 
323  virtual void add_spelling(const string & word,
324  Xapian::termcount freqinc) const;
325 
334  virtual void remove_spelling(const string & word,
335  Xapian::termcount freqdec) const;
336 
341  virtual TermList * open_synonym_termlist(const string & term) const;
342 
348  virtual TermList * open_synonym_keylist(const string & prefix) const;
349 
355  virtual void add_synonym(const string & term, const string & synonym) const;
356 
361  virtual void remove_synonym(const string & term, const string & synonym) const;
362 
367  virtual void clear_synonyms(const string & term) const;
368 
373  virtual string get_metadata(const string & key) const;
374 
383  virtual TermList * open_metadata_keylist(const std::string &prefix) const;
384 
389  virtual void set_metadata(const string & key, const string & value);
390 
396  virtual void reopen();
397 
400  virtual void close() = 0;
401 
403  // Modifying the database:
404  // =======================
405 
410  virtual void commit();
411 
413  virtual void cancel();
414 
419  void begin_transaction(bool flushed);
420 
425  void commit_transaction();
426 
431  void cancel_transaction();
432 
437  virtual Xapian::docid add_document(const Xapian::Document & document);
438 
443  virtual void delete_document(Xapian::docid did);
444 
449  virtual void delete_document(const string & unique_term);
450 
455  virtual void replace_document(Xapian::docid did,
456  const Xapian::Document & document);
457 
462  virtual Xapian::docid replace_document(const string & unique_term,
463  const Xapian::Document & document);
464 
475  virtual void request_document(Xapian::docid /*did*/) const;
476 
477  virtual Xapian::Document::Internal * collect_document(Xapian::docid did) const;
479 
485  virtual void write_changesets_to_fd(int fd,
486  const std::string & start_revision,
487  bool need_whole_db,
488  Xapian::ReplicationInfo * info);
489 
491  virtual string get_revision_info() const;
492 
503  virtual string get_uuid() const;
504 
512  virtual void invalidate_doc_object(Xapian::Document::Internal * obj) const;
513 
515  // Introspection methods:
516  // ======================
517 
524  virtual RemoteDatabase * as_remotedatabase();
525 };
526 
527 }
528 
529 #endif /* OM_HGUARD_DATABASE_H */

Documentation for Xapian (version 1.2.18).
Generated on Sun Jun 22 2014 by Doxygen 1.8.1.2.