xapian-core  2.0.0
databaseinternal.h
Go to the documentation of this file.
1 
4 /* Copyright 2004-2024 Olly Betts
5  * Copyright 2007,2008 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_DATABASEINTERNAL_H
23 #define XAPIAN_INCLUDED_DATABASEINTERNAL_H
24 
25 #include "internaltypes.h"
26 
27 #include <xapian/database.h>
28 #include <xapian/document.h>
29 #include <xapian/intrusive_ptr.h>
31 #include <xapian/postingiterator.h>
32 #include <xapian/termiterator.h>
33 #include <xapian/types.h>
34 #include <xapian/valueiterator.h>
35 
36 #include <string>
37 #include <string_view>
38 
42 
43 class LeafPostList;
44 
45 namespace Xapian {
46 namespace Internal {
47 class PostList;
48 }
49 }
51 
52 namespace Xapian {
53 
54 class Query;
55 struct ReplicationInfo;
56 
59  friend class Database;
60 
62  Internal& operator=(const Internal&) = delete;
63 
65  Internal(const Internal&) = delete;
66 
68  void dtor_called_();
69 
70  protected:
73  TRANSACTION_READONLY = -2, // Not a writable database shard.
74  TRANSACTION_UNIMPLEMENTED = -1, // Used by InMemory.
78  };
79 
87  Internal(transaction_state transaction_support)
88  : state(transaction_support) {}
89 
92 
94  bool is_read_only() const {
95  return state == TRANSACTION_READONLY;
96  }
97 
99  bool transaction_active() const { return state > 0; }
100 
114  void dtor_called() {
115  // Inline the check to exclude no-op cases (read-only and unimplemented).
116  if (state >= 0)
117  dtor_called_();
118  }
119 
120  public:
124  virtual ~Internal() {}
125 
127 
128  virtual size_type size() const;
129 
130  virtual void keep_alive();
131 
132  virtual void readahead_for_query(const Query& query) const;
133 
134  virtual doccount get_doccount() const = 0;
135 
137  virtual docid get_lastdocid() const = 0;
138 
140  virtual totallength get_total_length() const = 0;
141 
142  virtual termcount get_doclength(docid did) const = 0;
143 
148  virtual termcount get_unique_terms(docid did) const = 0;
149 
154  virtual termcount get_wdfdocmax(docid did) const = 0;
155 
164  virtual void get_freqs(std::string_view term,
165  doccount* termfreq_ptr,
166  termcount* collfreq_ptr) const = 0;
167 
175  virtual doccount get_value_freq(valueno slot) const = 0;
176 
184  virtual std::string get_value_lower_bound(valueno slot) const = 0;
185 
193  virtual std::string get_value_upper_bound(valueno slot) const = 0;
194 
200 
203 
205  virtual termcount get_wdf_upper_bound(std::string_view term) const = 0;
206 
208  virtual termcount get_unique_terms_lower_bound() const;
209 
211  virtual termcount get_unique_terms_upper_bound() const;
212 
213  virtual bool term_exists(std::string_view term) const = 0;
214 
216  virtual bool has_positions() const = 0;
217 
219  virtual PostList* open_post_list(std::string_view term) const = 0;
220 
231  virtual LeafPostList* open_leaf_post_list(std::string_view term,
232  bool need_read_pos) const = 0;
233 
243  virtual ValueList* open_value_list(valueno slot) const;
244 
245  virtual TermList* open_term_list(docid did) const = 0;
246 
252  virtual TermList* open_term_list_direct(docid did) const = 0;
253 
254  virtual TermList* open_allterms(std::string_view prefix) const = 0;
255 
257  std::string_view term) const = 0;
258 
273  virtual Document::Internal* open_document(docid did, bool lazy) const = 0;
274 
281  virtual TermList* open_spelling_termlist(std::string_view word) const;
282 
288  virtual TermList* open_spelling_wordlist() const;
289 
291  virtual doccount get_spelling_frequency(std::string_view word) const;
292 
300  virtual void add_spelling(std::string_view word,
301  termcount freqinc) const;
302 
313  virtual termcount remove_spelling(std::string_view word,
314  termcount freqdec) const;
315 
320  virtual TermList* open_synonym_termlist(std::string_view term) const;
321 
327  virtual TermList* open_synonym_keylist(std::string_view prefix) const;
328 
334  virtual void add_synonym(std::string_view term,
335  std::string_view synonym) const;
336 
341  virtual void remove_synonym(std::string_view term,
342  std::string_view synonym) const;
343 
348  virtual void clear_synonyms(std::string_view term) const;
349 
354  virtual std::string get_metadata(std::string_view key) const;
355 
363  virtual TermList* open_metadata_keylist(std::string_view prefix) const;
364 
369  virtual void set_metadata(std::string_view key, std::string_view value);
370 
376  virtual bool reopen();
377 
379  virtual void close() = 0;
380 
382  virtual void commit();
383 
385  virtual void cancel();
386 
388  virtual void begin_transaction(bool flushed);
389 
395  virtual void end_transaction(bool do_commit);
396 
397  virtual docid add_document(const Document& document);
398 
399  virtual void delete_document(docid did);
400 
402  virtual void delete_document(std::string_view unique_term);
403 
404  virtual void replace_document(docid did,
405  const Document& document);
406 
408  virtual docid replace_document(std::string_view unique_term,
409  const Document& document);
410 
426  virtual void request_document(docid did) const;
427 
433  virtual void write_changesets_to_fd(int fd,
434  std::string_view start_revision,
435  bool need_whole_db,
436  ReplicationInfo* info);
437 
439  virtual Xapian::rev get_revision() const;
440 
451  virtual std::string get_uuid() const;
452 
460  virtual void invalidate_doc_object(Document::Internal* obj) const;
461 
471  virtual int get_backend_info(std::string* path) const = 0;
472 
484  virtual void get_used_docid_range(docid& first,
485  docid& last) const;
486 
495  virtual bool locked() const;
496 
512  virtual Internal* update_lock(int flags);
513 
514  virtual std::string reconstruct_text(Xapian::docid did,
515  size_t length,
516  std::string_view prefix,
517  Xapian::termpos start_pos,
518  Xapian::termpos end_pos) const;
519 
521  virtual std::string get_description() const = 0;
522 };
523 
524 }
525 
526 #endif // XAPIAN_INCLUDED_DATABASEINTERNAL_H
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:62
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
Virtual base class for Database internals.
void dtor_called()
Helper to process uncommitted changes when a writable db is destroyed.
virtual termcount get_wdfdocmax(docid did) const =0
Get the max wdf in document.
virtual size_type size() const
virtual void set_metadata(std::string_view key, std::string_view value)
Set the metadata associated with a given key.
virtual bool term_exists(std::string_view term) const =0
virtual void commit()
Commit pending modifications to the database.
virtual TermList * open_term_list(docid did) const =0
virtual void get_used_docid_range(docid &first, docid &last) const
Find lowest and highest docids actually in use.
virtual void replace_document(docid did, const Document &document)
virtual std::string get_value_upper_bound(valueno slot) const =0
Get an upper bound on the values stored in the given value slot.
bool is_read_only() const
Test if this shard is read-only.
transaction_state
Transaction state enum.
virtual void begin_transaction(bool flushed)
Begin transaction.
virtual void delete_document(docid did)
virtual termcount get_unique_terms_lower_bound() const
Get a lower bound on the unique terms size of a document in this DB.
virtual std::string get_uuid() const
Get a UUID for the database.
virtual void close()=0
Close the database.
virtual std::string get_description() const =0
Return a string describing this object.
virtual TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
virtual std::string get_value_lower_bound(valueno slot) const =0
Get a lower bound on the values stored in the given value slot.
virtual void remove_synonym(std::string_view term, std::string_view synonym) const
Remove a synonym for a term.
virtual Xapian::rev get_revision() const
Get revision number of database (if meaningful).
virtual PositionList * open_position_list(docid did, std::string_view term) const =0
virtual void cancel()
Cancel pending modifications to the database.
virtual docid get_lastdocid() const =0
Return the last used document id of this (sub) database.
virtual TermList * open_spelling_termlist(std::string_view word) const
Create a termlist tree from trigrams of word.
virtual std::string get_metadata(std::string_view key) const
Get the metadata associated with a given key.
virtual void invalidate_doc_object(Document::Internal *obj) const
Notify the database that document is no longer valid.
virtual void write_changesets_to_fd(int fd, std::string_view start_revision, bool need_whole_db, ReplicationInfo *info)
Write a set of changesets to a file descriptor.
virtual termcount get_doclength_upper_bound() const =0
Get an upper bound on the length of a document in this DB.
virtual Document::Internal * open_document(docid did, bool lazy) const =0
Open a handle on a document.
virtual void clear_synonyms(std::string_view term) const
Clear all synonyms for a term.
virtual termcount get_doclength(docid did) const =0
virtual void add_spelling(std::string_view word, termcount freqinc) const
Add a word to the spelling dictionary.
virtual totallength get_total_length() const =0
Return the total length of all documents in this database.
void dtor_called_()
The "action required" helper for the dtor_called() helper.
virtual termcount get_wdf_upper_bound(std::string_view term) const =0
Get an upper bound on the wdf of term term.
virtual PostList * open_post_list(std::string_view term) const =0
Return a PostList suitable for use in a PostingIterator.
virtual int get_backend_info(std::string *path) const =0
Get backend information about this database.
virtual std::string reconstruct_text(Xapian::docid did, size_t length, std::string_view prefix, Xapian::termpos start_pos, Xapian::termpos end_pos) const
virtual TermList * open_allterms(std::string_view prefix) const =0
virtual bool has_positions() const =0
Check whether this database contains any positional information.
transaction_state state
Current transaction state.
Internal(const Internal &)=delete
Don't allow copying.
bool transaction_active() const
Test if a transaction is currently active.
virtual LeafPostList * open_leaf_post_list(std::string_view term, bool need_read_pos) const =0
Create a LeafPostList for use during a match.
virtual void readahead_for_query(const Query &query) const
virtual void add_synonym(std::string_view term, std::string_view synonym) const
Add a synonym for a term.
virtual void request_document(docid did) const
Request a document.
virtual doccount get_value_freq(valueno slot) const =0
Return the frequency of a given value slot.
virtual TermList * open_term_list_direct(docid did) const =0
Like open_term_list() but without MultiTermList wrapper.
virtual TermList * open_synonym_termlist(std::string_view term) const
Open a termlist returning synonyms for a term.
virtual bool locked() const
Return true if the database is open for writing.
Internal(transaction_state transaction_support)
Only constructable as a base class for derived classes.
virtual void end_transaction(bool do_commit)
End transaction.
virtual termcount get_unique_terms(docid did) const =0
Get the number of unique terms in document.
virtual void get_freqs(std::string_view term, doccount *termfreq_ptr, termcount *collfreq_ptr) const =0
Returns frequencies for a term.
virtual TermList * open_metadata_keylist(std::string_view prefix) const
Open a termlist returning each metadata key.
virtual Internal * update_lock(int flags)
Lock a read-only database for writing or unlock a writable database.
virtual TermList * open_synonym_keylist(std::string_view prefix) const
Open a termlist returning each term which has synonyms.
virtual doccount get_doccount() const =0
virtual termcount get_unique_terms_upper_bound() const
Get an upper bound on the unique terms size of a document in this DB.
virtual ~Internal()
We have virtual methods and want to be able to delete derived classes using a pointer to the base cla...
Internal & operator=(const Internal &)=delete
Don't allow assignment.
virtual ValueList * open_value_list(valueno slot) const
Open a value stream.
virtual bool reopen()
Reopen the database to the latest available revision.
virtual termcount remove_spelling(std::string_view word, termcount freqdec) const
Remove a word from the spelling dictionary.
virtual doccount get_spelling_frequency(std::string_view word) const
Return the number of times word was added as a spelling.
virtual docid add_document(const Document &document)
virtual termcount get_doclength_lower_bound() const =0
Get a lower bound on the length of a document in this DB.
An indexed database of documents.
Definition: database.h:75
Abstract base class for a document.
Class representing a document.
Definition: document.h:64
Abstract base class for postlists.
Definition: postlist.h:40
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:50
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Class representing a query.
Definition: query.h:45
Abstract base class for termlists.
Definition: termlist.h:42
Abstract base class for value streams.
Definition: valuelist.h:31
An indexed database of documents.
string term
Xapian::TermIterator::Internal TermList
Xapian::PositionIterator::Internal PositionList
Xapian::ValueIterator::Internal ValueList
Class representing a document.
Types used internally.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
XAPIAN_REVISION_TYPE rev
Revision number of a database.
Definition: types.h:108
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Definition: types.h:114
Class for iterating over term positions.
Class for iterating over a list of document ids.
Information about the steps involved in performing a replication.
Definition: replication.h:32
Class for iterating over a list of terms.
typedefs for Xapian
Class for iterating over document values.