35 #include <string_view>
42 return clamp_cast<MultiDatabase::size_type>(shards.size());
49 for (
auto&& shard : shards) {
50 if (shard->reopen()) {
60 for (
auto&& shard : shards) {
71 for (
auto&& shard : shards) {
72 postlists[count] = shard->open_post_list(
term);
78 delete postlists[--count];
103 auto shard = shards[shard_index];
105 TermList* res = shard->open_term_list(shard_did);
116 for (
auto&& shard : shards) {
117 termlists[count] = shard->open_allterms(prefix);
123 delete termlists[--count];
132 for (
auto&& shard : shards) {
133 if (shard->has_positions()) {
143 auto n_shards = shards.size();
146 return shard->open_position_list(shard_did,
term);
153 for (
auto&& shard : shards) {
154 auto old_result = result;
155 result += shard->get_doccount();
156 if (result < old_result)
168 Xapian::docid shard_lastdocid = shards[shard]->get_lastdocid();
169 if (shard_lastdocid == 0) {
174 result = max(result,
unshard(shard_lastdocid, shard, n_shards));
183 for (
auto&& shard : shards) {
184 auto old_result = result;
185 result += shard->get_total_length();
186 if (result < old_result)
207 for (
auto&& shard : shards) {
208 shard->get_freqs(
term, shard_tf_ptr, shard_cf_ptr);
210 auto old_tf = total_tf;
211 total_tf += *shard_tf_ptr;
212 if (total_tf < old_tf)
216 auto old_cf = total_cf;
217 total_cf += *shard_cf_ptr;
218 if (total_cf < old_cf)
234 for (
auto&& shard : shards) {
235 auto old_result = result;
236 result += shard->get_value_freq(slot);
237 if (result < old_result)
247 for (
auto&& shard : shards) {
248 string shard_result = shard->get_value_lower_bound(slot);
249 if (shard_result.empty())
251 if (result.empty() || shard_result < result)
252 result = std::move(shard_result);
261 for (
auto&& shard : shards) {
262 string shard_result = shard->get_value_upper_bound(slot);
263 if (shard_result > result)
264 result = std::move(shard_result);
278 static_assert(std::is_unsigned_v<Xapian::termcount>,
279 "Unsigned type required");
281 for (
auto&& shard : shards) {
292 for (
auto&& shard : shards) {
293 result = max(result, shard->get_doclength_upper_bound());
304 for (
auto&& shard : shards) {
305 result = max(result, shard->get_wdf_upper_bound(
term));
320 static_assert(std::is_unsigned_v<Xapian::termcount>,
321 "Unsigned type required");
323 for (
auto&& shard : shards) {
334 for (
auto&& shard : shards) {
335 result = max(result, shard->get_unique_terms_upper_bound());
346 for (
auto&& shard : shards) {
347 ValueList* vl = shard->open_value_list(slot);
354 delete valuelists[--count];
355 delete [] valuelists;
365 auto n_shards = shards.size();
368 return shard->get_doclength(shard_did);
376 auto n_shards = shards.size();
379 return shard->get_unique_terms(shard_did);
387 auto n_shards = shards.size();
390 return shard->get_wdfdocmax(shard_did);
398 auto n_shards = shards.size();
401 return shard->open_document(shard_did, lazy);
407 for (
auto&& shard : shards) {
408 if (shard->term_exists(
term))
417 for (
auto&& shard : shards) {
425 vector<TermList*> termlists;
426 termlists.reserve(shards.size());
429 for (
auto&& shard : shards) {
430 TermList* termlist = shard->open_spelling_termlist(word);
433 termlists.push_back(termlist);
438 for (
auto&& termlist : termlists)
447 vector<TermList*> termlists;
448 termlists.reserve(shards.size());
451 for (
auto&& shard : shards) {
452 TermList* termlist = shard->open_spelling_wordlist();
455 termlists.push_back(termlist);
458 return make_termlist_merger<FreqAdderOrTermList>(termlists);
460 for (
auto&& termlist : termlists)
470 for (
auto&& shard : shards) {
471 auto old_result = result;
472 result += shard->get_spelling_frequency(word);
473 if (result < old_result)
482 vector<TermList*> termlists;
483 termlists.reserve(shards.size());
486 for (
auto&& shard : shards) {
487 TermList* termlist = shard->open_synonym_termlist(
term);
490 termlists.push_back(termlist);
495 for (
auto&& termlist : termlists)
504 vector<TermList*> termlists;
505 termlists.reserve(shards.size());
508 for (
auto&& shard : shards) {
509 TermList* termlist = shard->open_synonym_keylist(prefix);
512 termlists.push_back(termlist);
517 for (
auto&& termlist : termlists)
526 return shards[0]->get_metadata(key);
532 return shards[0]->open_metadata_keylist(prefix);
539 for (
auto&& shard : shards) {
540 const string& sub_uuid = shard->get_uuid();
543 if (sub_uuid.empty())
555 for (
auto&& shard : shards) {
556 if (shard->locked()) {
570 "more than one subdatabase");
577 "more than one subdatabase");
598 for (
auto&& shard : shards) {
606 for (
auto&& shard : shards) {
614 for (
auto&& shard : shards) {
615 shard->begin_transaction(flushed);
622 for (
auto&& shard : shards) {
623 shard->end_transaction(do_commit);
633 if (
rare(did == 0)) {
635 "copydatabase to eliminate any gaps "
636 "before you can add more documents");
639 auto n_shards = shards.size();
641 shard->replace_document(
shard_docid(did, n_shards), doc);
648 auto n_shards = shards.size();
650 shard->delete_document(
shard_docid(did, n_shards));
656 for (
auto&& shard : shards) {
657 shard->delete_document(
term);
664 auto n_shards = shards.size();
666 shard->replace_document(
shard_docid(did, n_shards), doc);
672 auto n_shards = shards.size();
673 unique_ptr<PostList> pl(open_post_list(
term));
674 if (!pl || (pl->next(), pl->at_end())) {
678 if (
rare(did == 0)) {
680 "use copydatabase to eliminate any "
681 "gaps before you can add more "
685 return shard->add_document(doc);
689 auto replacing_shard = shards[
shard_number(result, n_shards)];
690 replacing_shard->replace_document(
shard_docid(result, n_shards), doc);
693 while (pl->next(), !pl->at_end()) {
696 shard->delete_document(
shard_docid(did, n_shards));
707 auto n_shards = shards.size();
710 shard->request_document(shard_did);
717 shards[0]->add_spelling(word, freqinc);
724 for (
auto&& shard : shards) {
725 freqdec = shard->remove_spelling(word, freqdec);
734 string_view synonym)
const
736 shards[0]->add_synonym(
term, synonym);
741 string_view synonym)
const
743 for (
auto&& shard : shards) {
744 shard->remove_synonym(
term, synonym);
751 for (
auto&& shard : shards) {
752 shard->clear_synonyms(
term);
759 shards[0]->set_metadata(key, value);
771 auto n_shards = shards.size();
774 return shard->reconstruct_text(shard_did, length, prefix,
782 for (
auto&& shard : shards) {
786 desc += shard->get_description();
Cast a value to a type, clamping out of range values.
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)