xapian-core  1.4.27
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 std::string;
41 using std::vector;
42 
43 class LeafPostList;
45 
49 
50 namespace Xapian {
51 
52 class Query;
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.
73 
74  bool transaction_active() const { return int(transaction_state) > 0; }
75 
78 
89  void dtor_called();
90 
91  public:
103  virtual ~Internal();
104 
108  virtual void keep_alive();
109 
110  virtual void readahead_for_query(const Xapian::Query & query);
111 
113  // Database statistics:
114  // ====================
115 
118  virtual Xapian::doccount get_doccount() const = 0;
119 
122  virtual Xapian::docid get_lastdocid() const = 0;
123 
125  virtual Xapian::totallength get_total_length() const = 0;
126 
137  virtual Xapian::termcount get_doclength(Xapian::docid did) const = 0;
138 
144  virtual Xapian::termcount get_unique_terms(Xapian::docid did) const = 0;
145 
154  virtual void get_freqs(const string & term,
155  Xapian::doccount * termfreq_ptr,
156  Xapian::termcount * collfreq_ptr) const = 0;
157 
165  virtual Xapian::doccount get_value_freq(Xapian::valueno slot) const = 0;
166 
174  virtual std::string get_value_lower_bound(Xapian::valueno slot) const = 0;
175 
183  virtual std::string get_value_upper_bound(Xapian::valueno slot) const = 0;
184 
190 
193 
195  virtual Xapian::termcount get_wdf_upper_bound(const std::string & term) const;
196 
201  virtual bool term_exists(const string & tname) const = 0;
202 
205  virtual bool has_positions() const = 0;
206 
208  // Data item access methods:
209  // =========================
210 
225  virtual LeafPostList * open_post_list(const string & tname) const = 0;
226 
236  virtual ValueList * open_value_list(Xapian::valueno slot) const;
237 
248  virtual TermList * open_term_list(Xapian::docid did) const = 0;
249 
259  virtual TermList * open_allterms(const string & prefix) const = 0;
260 
273  const string & tname) const = 0;
274 
291  open_document(Xapian::docid did, bool lazy) const = 0;
292 
299  virtual TermList * open_spelling_termlist(const string & word) const;
300 
306  virtual TermList * open_spelling_wordlist() const;
307 
309  virtual Xapian::doccount get_spelling_frequency(const string & word) const;
310 
318  virtual void add_spelling(const string & word,
319  Xapian::termcount freqinc) const;
320 
329  virtual void remove_spelling(const string & word,
330  Xapian::termcount freqdec) const;
331 
336  virtual TermList * open_synonym_termlist(const string & term) const;
337 
343  virtual TermList * open_synonym_keylist(const string & prefix) const;
344 
350  virtual void add_synonym(const string & term, const string & synonym) const;
351 
356  virtual void remove_synonym(const string & term, const string & synonym) const;
357 
362  virtual void clear_synonyms(const string & term) const;
363 
368  virtual string get_metadata(const string & key) const;
369 
378  virtual TermList * open_metadata_keylist(const std::string &prefix) const;
379 
384  virtual void set_metadata(const string & key, const string & value);
385 
391  virtual bool reopen();
392 
395  virtual void close() = 0;
396 
398  // Modifying the database:
399  // =======================
400 
405  virtual void commit();
406 
408  virtual void cancel();
409 
414  void begin_transaction(bool flushed);
415 
420  void commit_transaction();
421 
426  void cancel_transaction();
427 
432  virtual Xapian::docid add_document(const Xapian::Document & document);
433 
438  virtual void delete_document(Xapian::docid did);
439 
444  virtual void delete_document(const string & unique_term);
445 
450  virtual void replace_document(Xapian::docid did,
451  const Xapian::Document & document);
452 
457  virtual Xapian::docid replace_document(const string & unique_term,
458  const Xapian::Document & document);
459 
470  virtual void request_document(Xapian::docid /*did*/) const;
471 
474 
480  virtual void write_changesets_to_fd(int fd,
481  const std::string & start_revision,
482  bool need_whole_db,
483  Xapian::ReplicationInfo * info);
484 
486  virtual string get_revision_info() const;
487 
498  virtual string get_uuid() const;
499 
507  virtual void invalidate_doc_object(Xapian::Document::Internal * obj) const;
508 
518  virtual int get_backend_info(string * path) const = 0;
519 
525  virtual void get_used_docid_range(Xapian::docid & first,
526  Xapian::docid & last) const;
527 
536  virtual bool locked() const;
537 };
538 
539 }
540 
541 #endif /* OM_HGUARD_DATABASE_H */
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
void operator=(const Internal &)
Assignment is not allowed.
virtual void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
Definition: database.cc:186
typedefs for Xapian
virtual Xapian::doccount get_value_freq(Xapian::valueno slot) const =0
Return the frequency of a given value slot.
virtual TermList * open_term_list(Xapian::docid did) const =0
Open a term list.
virtual ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
Definition: database.cc:211
bool transaction_active() const
Definition: database.h:74
virtual Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
Definition: database.cc:161
virtual void commit()
Commit pending modifications to the database.
Definition: database.cc:102
virtual TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
Definition: database.cc:226
Base class for databases.
Definition: database.h:57
void begin_transaction(bool flushed)
Begin a transaction.
Definition: database.cc:116
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:77
virtual bool reopen()
Reopen the database to the latest available revision.
Definition: database.cc:312
virtual Xapian::termcount get_wdf_upper_bound(const std::string &term) const
Get an upper bound on the wdf of term term.
Definition: database.cc:75
virtual void clear_synonyms(const string &term) const
Clear all synonyms for a term.
Definition: database.cc:286
A document in the database, possibly plus modifications.
Definition: document.h:43
Abstract base class for termlists.
Definition: termlist.h:39
virtual bool has_positions() const =0
Check whether this database contains any positional information.
virtual void set_metadata(const string &key, const string &value)
Set the metadata associated with a given key.
Definition: database.cc:306
Abstract base class for leaf postlists.
Definition: leafpostlist.h:39
virtual LeafPostList * open_post_list(const string &tname) const =0
Open a posting list.
virtual Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
Definition: database.cc:67
virtual void readahead_for_query(const Xapian::Query &query)
Definition: database.cc:54
Class for iterating over term positions.
virtual string get_uuid() const
Get a UUID for the database.
Definition: database.cc:347
virtual bool term_exists(const string &tname) const =0
Check whether a given term is in the database.
virtual void delete_document(Xapian::docid did)
Delete a document in the database.
Definition: database.cc:169
virtual PositionList * open_position_list(Xapian::docid did, const string &tname) const =0
Open a position list for the given term in the given document.
enum Xapian::Database::Internal::@2 transaction_state
Transaction state.
virtual Xapian::termcount get_unique_terms(Xapian::docid did) const =0
Get the number of unique term in document.
virtual void add_synonym(const string &term, const string &synonym) const
Add a synonym for a term.
Definition: database.cc:274
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
virtual std::string get_value_upper_bound(Xapian::valueno slot) const =0
Get an upper bound on the values stored in the given value slot.
virtual Xapian::docid get_lastdocid() const =0
Return the last used document id of this (sub) database.
virtual Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
Definition: database.cc:59
virtual bool locked() const
Return true if the database is open for writing.
Definition: database.cc:366
virtual TermList * open_synonym_termlist(const string &term) const
Open a termlist returning synonyms for a term.
Definition: database.cc:256
virtual Xapian::Document::Internal * collect_document(Xapian::docid did) const
Request and later collect a document from the database.
Definition: database.cc:326
virtual TermList * open_allterms(const string &prefix) const =0
Open an allterms list.
virtual void remove_synonym(const string &term, const string &synonym) const
Remove a synonym for a term.
Definition: database.cc:280
API for working with Xapian databases.
virtual string get_revision_info() const
Get a string describing the current revision of the database.
Definition: database.cc:341
virtual ~Internal()
Destroy the database.
Definition: database.cc:42
virtual int get_backend_info(string *path) const =0
Get backend information about this database.
Information about the steps involved in performing a replication.
Definition: replication.h:33
Class for iterating over document values.
virtual void remove_spelling(const string &word, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
Definition: database.cc:250
Xapian::ValueIterator::Internal ValueList
Definition: database.h:48
RemoteDatabase is the baseclass for remote database implementations.
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:49
virtual Xapian::doccount get_spelling_frequency(const string &word) const
Return the number of times word was added as a spelling.
Definition: database.cc:235
virtual Xapian::totallength get_total_length() const =0
Return the total length of all documents in this database.
virtual std::string get_value_lower_bound(Xapian::valueno slot) const =0
Get a lower bound on the values stored in the given value slot.
virtual TermList * open_metadata_keylist(const std::string &prefix) const
Open a termlist returning each metadata key.
Definition: database.cc:298
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
void commit_transaction()
Commit a transaction.
Definition: database.cc:134
virtual TermList * open_spelling_termlist(const string &word) const
Create a termlist tree from trigrams of word.
Definition: database.cc:217
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Xapian::TermIterator::Internal TermList
Definition: database.h:44
virtual string get_metadata(const string &key) const
Get the metadata associated with a given key.
Definition: database.cc:292
virtual void add_spelling(const string &word, Xapian::termcount freqinc) const
Add a word to the spelling dictionary.
Definition: database.cc:244
virtual void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const =0
Returns frequencies for a term.
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
virtual void invalidate_doc_object(Xapian::Document::Internal *obj) const
Notify the database that document is no longer valid.
Definition: database.cc:353
void dtor_called()
Internal method to perform cleanup when a writable database is destroyed with uncommitted changes...
Definition: database.cc:87
virtual void close()=0
Close the database.
virtual Xapian::doccount get_doccount() const =0
Return the number of docs in this (sub) database.
virtual void write_changesets_to_fd(int fd, const std::string &start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
Write a set of changesets to a file descriptor.
Definition: database.cc:335
virtual void cancel()
Cancel pending modifications to the database.
Definition: database.cc:109
virtual void request_document(Xapian::docid) const
Request and later collect a document from the database.
Definition: database.cc:321
virtual void keep_alive()
Send a keep-alive signal to a remote database, to stop it from timing out.
Definition: database.cc:47
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:47
API for working with documents.
virtual Xapian::termcount get_doclength(Xapian::docid did) const =0
Get the length of a given document.
Class for iterating over a list of terms.
virtual void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
Find lowest and highest docids actually in use.
Definition: database.cc:359
virtual Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const =0
Open a document.
void cancel_transaction()
Cancel a transaction.
Definition: database.cc:149
A handle representing a document in a Xapian database.
Definition: document.h:61
Types used internally.
virtual TermList * open_synonym_keylist(const string &prefix) const
Open a termlist returning each term which has synonyms.
Definition: database.cc:265