xapian-core  2.0.0
multi_database.h
Go to the documentation of this file.
1 
4 /* Copyright 2017,2019,2024 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_MULTI_DATABASE_H
22 #define XAPIAN_INCLUDED_MULTI_DATABASE_H
23 
24 #include "api/termlist.h"
26 #include "backends/valuelist.h"
27 
28 #include <string_view>
29 
30 class LeafPostList;
31 class Matcher;
33 
34 namespace Xapian {
35 struct ReplicationInfo;
36 namespace Internal {
37 class PostList;
38 }
39 }
40 
42 
45  friend class Matcher;
46  friend class PostListTree;
47  friend class ValueStreamDocument;
48  friend class Xapian::Database;
49 
51 
52  public:
53  explicit MultiDatabase(size_type reserve_size, bool read_only)
54  : Xapian::Database::Internal(read_only ?
57  shards(reserve_size) {}
58 
59  size_type size() const;
60 
61  void reserve(size_type new_size) { shards.reserve(new_size); }
62 
64  shards.push_back(shard);
65  }
66 
67  bool reopen();
68 
69  void close();
70 
71  PostList* open_post_list(std::string_view term) const;
72 
73  LeafPostList* open_leaf_post_list(std::string_view term,
74  bool need_read_pos) const;
75 
77 
79 
80  TermList* open_allterms(std::string_view prefix) const;
81 
82  bool has_positions() const;
83 
85  std::string_view term) const;
87 
89 
91 
92  void get_freqs(std::string_view term,
93  Xapian::doccount* tf_ptr,
94  Xapian::termcount* cf_ptr) const;
95 
97 
98  std::string get_value_lower_bound(Xapian::valueno slot) const;
99 
100  std::string get_value_upper_bound(Xapian::valueno slot) const;
101 
103 
105 
106  Xapian::termcount get_wdf_upper_bound(std::string_view term) const;
107 
109 
111 
113 
115 
117 
119 
121  bool lazy) const;
122 
123  bool term_exists(std::string_view term) const;
124 
125  void keep_alive();
126 
127  TermList* open_spelling_termlist(std::string_view word) const;
128 
130 
131  Xapian::doccount get_spelling_frequency(std::string_view word) const;
132 
133  TermList* open_synonym_termlist(std::string_view term) const;
134 
135  TermList* open_synonym_keylist(std::string_view prefix) const;
136 
137  std::string get_metadata(std::string_view key) const;
138 
139  TermList* open_metadata_keylist(std::string_view prefix) const;
140 
141  std::string get_uuid() const;
142 
143  bool locked() const;
144 
145  void write_changesets_to_fd(int fd,
146  std::string_view start_revision,
147  bool need_whole_db,
149 
151 
152  Xapian::rev get_revision() const;
153 
154  int get_backend_info(std::string* path) const;
155 
156  void commit();
157 
158  void cancel();
159 
160  void begin_transaction(bool flushed);
161 
162  void end_transaction(bool do_commit);
163 
165 
166  void delete_document(Xapian::docid did);
167 
168  void delete_document(std::string_view term);
169 
170  void replace_document(Xapian::docid did, const Xapian::Document& doc);
171 
172  Xapian::docid replace_document(std::string_view term,
173  const Xapian::Document& doc);
174 
175  void request_document(Xapian::docid did) const;
176 
177  void add_spelling(std::string_view word, Xapian::termcount freqinc) const;
178 
179  Xapian::termcount remove_spelling(std::string_view word,
180  Xapian::termcount freqdec) const;
181 
182  void add_synonym(std::string_view term, std::string_view synonym) const;
183 
184  void remove_synonym(std::string_view term,
185  std::string_view synonym) const;
186 
187  void clear_synonyms(std::string_view term) const;
188 
189  void set_metadata(std::string_view key, std::string_view value);
190 
191  std::string reconstruct_text(Xapian::docid did,
192  size_t length,
193  std::string_view prefix,
194  Xapian::termpos start_pos,
195  Xapian::termpos end_pos) const;
196 
197  std::string get_description() const;
198 };
199 
200 #endif // XAPIAN_INCLUDED_MULTI_DATABASE_H
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
Sharded database backend.
Xapian::docid get_lastdocid() const
Return the last used document id of this (sub) database.
bool locked() const
Return true if the database is open for writing.
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
Xapian::termcount get_doclength(Xapian::docid did) const
TermList * open_synonym_termlist(std::string_view term) const
Open a termlist returning synonyms for a term.
Xapian::doccount get_spelling_frequency(std::string_view word) const
Return the number of times word was added as a spelling.
void add_spelling(std::string_view word, Xapian::termcount freqinc) const
Add a word to the spelling dictionary.
PostList * open_post_list(std::string_view term) const
Return a PostList suitable for use in a PostingIterator.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
size_type size() const
TermList * open_allterms(std::string_view prefix) const
TermList * open_metadata_keylist(std::string_view prefix) const
Open a termlist returning each metadata key.
TermList * open_term_list(Xapian::docid did) const
void push_back(Xapian::Database::Internal *shard)
std::string get_uuid() const
Get a UUID for the database.
MultiDatabase(size_type reserve_size, bool read_only)
Xapian::rev get_revision() const
Get revision number of database (if meaningful).
bool term_exists(std::string_view term) const
Xapian::SmallVectorI< Xapian::Database::Internal > shards
Xapian::termcount remove_spelling(std::string_view word, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
LeafPostList * open_leaf_post_list(std::string_view term, bool need_read_pos) const
Create a LeafPostList for use during a match.
void clear_synonyms(std::string_view term) const
Clear all synonyms for a term.
bool has_positions() const
Check whether this database contains any positional information.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
Xapian::termcount get_wdfdocmax(Xapian::docid did) const
Get the max wdf in document.
std::string get_metadata(std::string_view key) const
Get the metadata associated with a given key.
void add_synonym(std::string_view term, std::string_view synonym) const
Add a synonym for a term.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
TermList * open_spelling_termlist(std::string_view word) const
Create a termlist tree from trigrams of word.
std::string reconstruct_text(Xapian::docid did, size_t length, std::string_view prefix, Xapian::termpos start_pos, Xapian::termpos end_pos) const
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
TermList * open_synonym_keylist(std::string_view prefix) const
Open a termlist returning each term which has synonyms.
void invalidate_doc_object(Xapian::Document::Internal *obj) const
Notify the database that document is no longer valid.
PositionList * open_position_list(Xapian::docid did, std::string_view term) const
Xapian::termcount get_wdf_upper_bound(std::string_view term) const
Get an upper bound on the wdf of term term.
ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
Xapian::doccount get_doccount() const
int get_backend_info(std::string *path) const
Get backend information about this database.
void remove_synonym(std::string_view term, std::string_view synonym) const
Remove a synonym for a term.
void request_document(Xapian::docid did) const
Request a document.
Xapian::docid add_document(const Xapian::Document &doc)
void end_transaction(bool do_commit)
End transaction.
void commit()
Commit pending modifications to the database.
void begin_transaction(bool flushed)
Begin transaction.
Xapian::termcount get_unique_terms_upper_bound() const
Get an upper bound on the unique terms size of a document in this DB.
void delete_document(Xapian::docid did)
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
void set_metadata(std::string_view key, std::string_view value)
Set the metadata associated with a given key.
TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
void cancel()
Cancel pending modifications to the database.
Xapian::termcount get_unique_terms_lower_bound() const
Get a lower bound on the unique terms size of a document in this DB.
void reserve(size_type new_size)
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Open a handle on a document.
bool reopen()
Reopen the database to the latest available revision.
void replace_document(Xapian::docid did, const Xapian::Document &doc)
void write_changesets_to_fd(int fd, std::string_view start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
Write a set of changesets to a file descriptor.
std::string get_description() const
Return a string describing this object.
TermList * open_term_list_direct(Xapian::docid did) const
Like open_term_list() but without MultiTermList wrapper.
void close()
Close the database.
void get_freqs(std::string_view term, Xapian::doccount *tf_ptr, Xapian::termcount *cf_ptr) const
Returns frequencies for a term.
A document which gets its values from a ValueStreamManager.
Virtual base class for Database internals.
Internal(const Internal &)=delete
Don't allow copying.
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
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
void push_back(TI *elt)
Definition: smallvector.h:545
void reserve(std::size_t n)
Definition: smallvector.h:454
Abstract base class for termlists.
Definition: termlist.h:42
Abstract base class for value streams.
Definition: valuelist.h:31
string term
Virtual base class for Database internals.
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
Information about the steps involved in performing a replication.
Definition: replication.h:32
Abstract base class for termlists.
Abstract base class for value streams.