34 #include <string_view>
48 for (
auto&& shard : shards) {
49 if (shard->reopen()) {
59 for (
auto&& shard : shards) {
70 for (
auto&& shard : shards) {
71 postlists[count] = shard->open_post_list(
term);
77 delete postlists[--count];
102 auto shard = shards[shard_index];
104 TermList* res = shard->open_term_list(shard_did);
115 for (
auto&& shard : shards) {
116 termlists[count] = shard->open_allterms(prefix);
122 delete termlists[--count];
131 for (
auto&& shard : shards) {
132 if (shard->has_positions()) {
142 auto n_shards = shards.size();
145 return shard->open_position_list(shard_did,
term);
152 for (
auto&& shard : shards) {
153 auto old_result = result;
154 result += shard->get_doccount();
155 if (result < old_result)
167 Xapian::docid shard_lastdocid = shards[shard]->get_lastdocid();
168 if (shard_lastdocid == 0) {
173 result = max(result,
unshard(shard_lastdocid, shard, n_shards));
182 for (
auto&& shard : shards) {
183 auto old_result = result;
184 result += shard->get_total_length();
185 if (result < old_result)
206 for (
auto&& shard : shards) {
207 shard->get_freqs(
term, shard_tf_ptr, shard_cf_ptr);
209 auto old_tf = total_tf;
210 total_tf += *shard_tf_ptr;
211 if (total_tf < old_tf)
215 auto old_cf = total_cf;
216 total_cf += *shard_cf_ptr;
217 if (total_cf < old_cf)
233 for (
auto&& shard : shards) {
234 auto old_result = result;
235 result += shard->get_value_freq(slot);
236 if (result < old_result)
246 for (
auto&& shard : shards) {
247 string shard_result = shard->get_value_lower_bound(slot);
248 if (shard_result.empty())
250 if (result.empty() || shard_result < result)
251 result = std::move(shard_result);
260 for (
auto&& shard : shards) {
261 string shard_result = shard->get_value_upper_bound(slot);
262 if (shard_result > result)
263 result = std::move(shard_result);
277 static_assert(std::is_unsigned_v<Xapian::termcount>,
278 "Unsigned type required");
280 for (
auto&& shard : shards) {
291 for (
auto&& shard : shards) {
292 result = max(result, shard->get_doclength_upper_bound());
303 for (
auto&& shard : shards) {
304 result = max(result, shard->get_wdf_upper_bound(
term));
319 static_assert(std::is_unsigned_v<Xapian::termcount>,
320 "Unsigned type required");
322 for (
auto&& shard : shards) {
333 for (
auto&& shard : shards) {
334 result = max(result, shard->get_unique_terms_upper_bound());
345 for (
auto&& shard : shards) {
346 ValueList* vl = shard->open_value_list(slot);
353 delete valuelists[--count];
354 delete [] valuelists;
364 auto n_shards = shards.size();
367 return shard->get_doclength(shard_did);
375 auto n_shards = shards.size();
378 return shard->get_unique_terms(shard_did);
386 auto n_shards = shards.size();
389 return shard->get_wdfdocmax(shard_did);
397 auto n_shards = shards.size();
400 return shard->open_document(shard_did, lazy);
406 for (
auto&& shard : shards) {
407 if (shard->term_exists(
term))
416 for (
auto&& shard : shards) {
424 vector<TermList*> termlists;
425 termlists.reserve(shards.size());
428 for (
auto&& shard : shards) {
429 TermList* termlist = shard->open_spelling_termlist(word);
432 termlists.push_back(termlist);
437 for (
auto&& termlist : termlists)
446 vector<TermList*> termlists;
447 termlists.reserve(shards.size());
450 for (
auto&& shard : shards) {
451 TermList* termlist = shard->open_spelling_wordlist();
454 termlists.push_back(termlist);
457 return make_termlist_merger<FreqAdderOrTermList>(termlists);
459 for (
auto&& termlist : termlists)
469 for (
auto&& shard : shards) {
470 auto old_result = result;
471 result += shard->get_spelling_frequency(word);
472 if (result < old_result)
481 vector<TermList*> termlists;
482 termlists.reserve(shards.size());
485 for (
auto&& shard : shards) {
486 TermList* termlist = shard->open_synonym_termlist(
term);
489 termlists.push_back(termlist);
494 for (
auto&& termlist : termlists)
503 vector<TermList*> termlists;
504 termlists.reserve(shards.size());
507 for (
auto&& shard : shards) {
508 TermList* termlist = shard->open_synonym_keylist(prefix);
511 termlists.push_back(termlist);
516 for (
auto&& termlist : termlists)
525 return shards[0]->get_metadata(key);
531 return shards[0]->open_metadata_keylist(prefix);
538 for (
auto&& shard : shards) {
539 const string& sub_uuid = shard->get_uuid();
542 if (sub_uuid.empty())
554 for (
auto&& shard : shards) {
555 if (shard->locked()) {
569 "more than one subdatabase");
576 "more than one subdatabase");
597 for (
auto&& shard : shards) {
605 for (
auto&& shard : shards) {
613 for (
auto&& shard : shards) {
614 shard->begin_transaction(flushed);
621 for (
auto&& shard : shards) {
622 shard->end_transaction(do_commit);
632 if (
rare(did == 0)) {
634 "copydatabase to eliminate any gaps "
635 "before you can add more documents");
638 auto n_shards = shards.size();
640 shard->replace_document(
shard_docid(did, n_shards), doc);
647 auto n_shards = shards.size();
649 shard->delete_document(
shard_docid(did, n_shards));
655 for (
auto&& shard : shards) {
656 shard->delete_document(
term);
663 auto n_shards = shards.size();
665 shard->replace_document(
shard_docid(did, n_shards), doc);
671 auto n_shards = shards.size();
672 unique_ptr<PostList> pl(open_post_list(
term));
673 if (!pl || (pl->next(), pl->at_end())) {
677 if (
rare(did == 0)) {
679 "use copydatabase to eliminate any "
680 "gaps before you can add more "
684 return shard->add_document(doc);
688 auto replacing_shard = shards[
shard_number(result, n_shards)];
689 replacing_shard->replace_document(
shard_docid(result, n_shards), doc);
692 while (pl->next(), !pl->at_end()) {
695 shard->delete_document(
shard_docid(did, n_shards));
706 auto n_shards = shards.size();
709 shard->request_document(shard_did);
716 shards[0]->add_spelling(word, freqinc);
723 for (
auto&& shard : shards) {
724 freqdec = shard->remove_spelling(word, freqdec);
733 string_view synonym)
const
735 shards[0]->add_synonym(
term, synonym);
740 string_view synonym)
const
742 for (
auto&& shard : shards) {
743 shard->remove_synonym(
term, synonym);
750 for (
auto&& shard : shards) {
751 shard->clear_synonyms(
term);
758 shards[0]->set_metadata(key, value);
770 auto n_shards = shards.size();
773 return shard->reconstruct_text(shard_did, length, prefix,
781 for (
auto&& shard : shards) {
785 desc += shard->get_description();
Abstract base class for leaf postlists.
Class for merging AllTermsList objects from subdatabases.
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.
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
std::string get_uuid() const
Get a UUID for the database.
Xapian::rev get_revision() const
Get revision number of database (if meaningful).
bool term_exists(std::string_view term) const
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.
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.
Class for merging PostList objects from subdatabases.
Adapter class for a TermList in a multidatabase.
Class for merging ValueList objects from subdatabases.
DatabaseError indicates some sort of database related error.
Xapian::doccount size_type
Abstract base class for a document.
Class representing a document.
Abstract base class for postlists.
InvalidOperationError indicates the API was used in an invalid way.
Abstract base class for iterating term positions in a document.
Abstract base class for termlists.
size_t shard_index
Which shard of a multidatabase this is from.
Abstract base class for value streams.
#define UNSIGNED_OVERFLOW_OK(X)
Multi-database support functions.
Xapian::doccount shard_number(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to shard number.
Xapian::docid shard_docid(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to the docid in the shard.
Xapian::docid unshard(Xapian::docid shard_did, Xapian::doccount shard, Xapian::doccount n_shards)
Convert shard number and shard docid to docid in multi-db.
Class for merging AllTermsList objects from subdatabases.
Sharded database backend.
Class for merging PostList objects from subdatabases.
Adapter class for a TermList in a multidatabase.
Class for merging ValueList objects from subdatabases.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Negate unsigned integer, avoiding compiler warnings.
constexpr std::enable_if_t< std::is_unsigned_v< T >, T > negate_unsigned(T value)
Merge two TermList objects using an OR operation.
Information about the steps involved in performing a replication.
Build tree to merge TermList objects.
TermList * make_termlist_merger(std::vector< TermList * > &termlists)