xapian-core  1.4.19
database.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002 Ananova Ltd
6  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2011,2013,2014,2015,2016 Olly Betts
7  * Copyright 2006,2008 Lemur Consulting Ltd
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef OM_HGUARD_DATABASE_H
26 #define OM_HGUARD_DATABASE_H
27 
28 #include <string>
29 
30 #include "internaltypes.h"
31 
32 #include "xapian/intrusive_ptr.h"
33 #include <xapian/types.h>
34 #include <xapian/database.h>
35 #include <xapian/document.h>
37 #include <xapian/termiterator.h>
38 #include <xapian/valueiterator.h>
39 
40 using namespace std;
41 
42 class LeafPostList;
44 
48 
49 namespace Xapian {
50 
51 class Query;
52 struct ReplicationInfo;
53 
57  private:
59  Internal(const Internal &);
60 
62  void operator=(const Internal &);
63 
64  protected:
66  enum {
67  TRANSACTION_UNIMPLEMENTED = -1, // Used by InMemory.
68  TRANSACTION_NONE = 0,
69  TRANSACTION_UNFLUSHED = 1,
70  TRANSACTION_FLUSHED = 2
71  } transaction_state;
72 
73  bool transaction_active() const { return int(transaction_state) > 0; }
74 
76  Internal() : transaction_state(TRANSACTION_NONE) { }
77 
88  void dtor_called();
89 
90  public:
102  virtual ~Internal();
103 
107  virtual void keep_alive();
108 
109  virtual void readahead_for_query(const Xapian::Query & query);
110 
112  // Database statistics:
113  // ====================
114 
117  virtual Xapian::doccount get_doccount() const = 0;
118 
121  virtual Xapian::docid get_lastdocid() const = 0;
122 
124  virtual Xapian::totallength get_total_length() const = 0;
125 
136  virtual Xapian::termcount get_doclength(Xapian::docid did) const = 0;
137 
143  virtual Xapian::termcount get_unique_terms(Xapian::docid did) const = 0;
144 
153  virtual void get_freqs(const string & term,
154  Xapian::doccount * termfreq_ptr,
155  Xapian::termcount * collfreq_ptr) const = 0;
156 
167  virtual Xapian::doccount get_value_freq(Xapian::valueno slot) const = 0;
168 
176  virtual std::string get_value_lower_bound(Xapian::valueno slot) const = 0;
177 
185  virtual std::string get_value_upper_bound(Xapian::valueno slot) const = 0;
186 
188  virtual Xapian::termcount get_doclength_lower_bound() const;
189 
191  virtual Xapian::termcount get_doclength_upper_bound() const;
192 
194  virtual Xapian::termcount get_wdf_upper_bound(const std::string & term) const;
195 
200  virtual bool term_exists(const string & tname) const = 0;
201 
204  virtual bool has_positions() const = 0;
205 
207  // Data item access methods:
208  // =========================
209 
224  virtual LeafPostList * open_post_list(const string & tname) const = 0;
225 
235  virtual ValueList * open_value_list(Xapian::valueno slot) const;
236 
247  virtual TermList * open_term_list(Xapian::docid did) const = 0;
248 
258  virtual TermList * open_allterms(const string & prefix) const = 0;
259 
271  virtual PositionList * open_position_list(Xapian::docid did,
272  const string & tname) const = 0;
273 
290  open_document(Xapian::docid did, bool lazy) const = 0;
291 
298  virtual TermList * open_spelling_termlist(const string & word) const;
299 
305  virtual TermList * open_spelling_wordlist() const;
306 
308  virtual Xapian::doccount get_spelling_frequency(const string & word) const;
309 
317  virtual void add_spelling(const string & word,
318  Xapian::termcount freqinc) const;
319 
328  virtual void remove_spelling(const string & word,
329  Xapian::termcount freqdec) const;
330 
335  virtual TermList * open_synonym_termlist(const string & term) const;
336 
342  virtual TermList * open_synonym_keylist(const string & prefix) const;
343 
349  virtual void add_synonym(const string & term, const string & synonym) const;
350 
355  virtual void remove_synonym(const string & term, const string & synonym) const;
356 
361  virtual void clear_synonyms(const string & term) const;
362 
367  virtual string get_metadata(const string & key) const;
368 
377  virtual TermList * open_metadata_keylist(const std::string &prefix) const;
378 
383  virtual void set_metadata(const string & key, const string & value);
384 
390  virtual bool reopen();
391 
394  virtual void close() = 0;
395 
397  // Modifying the database:
398  // =======================
399 
404  virtual void commit();
405 
407  virtual void cancel();
408 
413  void begin_transaction(bool flushed);
414 
419  void commit_transaction();
420 
425  void cancel_transaction();
426 
431  virtual Xapian::docid add_document(const Xapian::Document & document);
432 
437  virtual void delete_document(Xapian::docid did);
438 
443  virtual void delete_document(const string & unique_term);
444 
449  virtual void replace_document(Xapian::docid did,
450  const Xapian::Document & document);
451 
456  virtual Xapian::docid replace_document(const string & unique_term,
457  const Xapian::Document & document);
458 
469  virtual void request_document(Xapian::docid /*did*/) const;
470 
471  virtual Xapian::Document::Internal * collect_document(Xapian::docid did) const;
473 
479  virtual void write_changesets_to_fd(int fd,
480  const std::string & start_revision,
481  bool need_whole_db,
482  Xapian::ReplicationInfo * info);
483 
485  virtual string get_revision_info() const;
486 
497  virtual string get_uuid() const;
498 
506  virtual void invalidate_doc_object(Xapian::Document::Internal * obj) const;
507 
517  virtual int get_backend_info(string * path) const = 0;
518 
524  virtual void get_used_docid_range(Xapian::docid & first,
525  Xapian::docid & last) const;
526 
535  virtual bool locked() const;
536 };
537 
538 }
539 
540 #endif /* OM_HGUARD_DATABASE_H */
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
int close(FD &fd)
Definition: fd.h:63
typedefs for Xapian
bool transaction_active() const
Definition: database.h:73
Base class for databases.
Definition: database.h:56
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Definition: types.h:139
Internal()
Create a database - called only by derived classes.
Definition: database.h:76
A document in the database, possibly plus modifications.
Definition: document.h:41
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
Abstract base class for leaf postlists.
Definition: leafpostlist.h:38
Class for iterating over term positions.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
API for working with Xapian databases.
Information about the steps involved in performing a replication.
Definition: replication.h:33
Class for iterating over document values.
Xapian::ValueIterator::Internal ValueList
Definition: database.h:47
RemoteDatabase is the baseclass for remote database implementations.
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:49
Abstract base class for value streams.
Definition: valuelist.h:31
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
Definition: api_anydb.cc:63
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Xapian::TermIterator::Internal TermList
Definition: database.h:43
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Class representing a query.
Definition: query.h:46
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
Xapian::PositionIterator::Internal PositionList
Definition: database.h:46
API for working with documents.
Class for iterating over a list of terms.
A handle representing a document in a Xapian database.
Definition: document.h:61
Types used internally.