95 return internal->reopen();
107 return internal->size();
114 const char* msg = read_only ?
115 "Database::add_database(): Can't add a Database to itself" :
116 "WritableDatabase::add_database(): Can't add a WritableDatabase "
127 auto my_size =
internal->size();
128 if (my_size == 0 && o_size == 1) {
161 "Database to a WritableDatabase");
166 auto new_size = my_size + o_size;
170 if (my_size) multi_db->
push_back(
internal.get());
185 for (
auto&& shard : o_multi->shards) {
217 return internal->has_positions();
235 return internal->get_doccount();
241 return internal->get_lastdocid();
248 if (
rare(doc_count == 0))
252 return total_length / double(doc_count);
258 return internal->get_total_length();
268 internal->get_freqs(
term, &result, NULL);
279 internal->get_freqs(
term, NULL, &result);
286 return internal->get_value_freq(slot);
292 return internal->get_value_lower_bound(slot);
298 return internal->get_value_upper_bound(slot);
304 return internal->get_doclength_lower_bound();
310 return internal->get_doclength_upper_bound();
319 return internal->get_wdf_upper_bound(
term);
325 return internal->get_unique_terms_lower_bound();
331 return internal->get_unique_terms_upper_bound();
346 return internal->get_doclength(did);
355 return internal->get_unique_terms(did);
364 return internal->get_wdfdocmax(did);
381 return internal->term_exists(
term);
387 internal->keep_alive();
393 string desc =
"Database(";
394 desc +=
internal->get_description();
401 unsigned max_edit_distance)
const
403 if (word.size() <= 1 || max_edit_distance == 0)
406 max_edit_distance = min(max_edit_distance,
unsigned(word.size() - 1));
414 int edist_best = max_edit_distance;
419 if (
rare(ret == merger.get())) {
423 if (
rare(ret)) merger.reset(ret);
425 const string&
term = merger->get_termname();
442 int edist = edcalc(
term, edist_best);
445 if (edist <= edist_best) {
452 if (
rare(edist == 0)) {
457 if (edist < edist_best || freq > freq_best) {
459 "\" edist " << edist <<
" freq " << freq);
466 if (freq_best < freq_exact)
492 if (
rare(key.empty()))
495 return internal->get_metadata(key);
507 return internal->get_uuid();
513 return internal->locked();
529 return internal->get_revision();
535 std::string_view prefix,
539 return internal->reconstruct_text(did, length, prefix, start_pos, end_pos);
551 internal->begin_transaction(flushed);
557 internal->end_transaction(do_commit);
563 return internal->add_document(doc);
569 internal->delete_document(did);
578 internal->delete_document(
term);
587 internal->replace_document(did, doc);
596 return internal->replace_document(
term, doc);
603 internal->add_spelling(word, freqinc);
610 return internal->remove_spelling(word, freqdec);
615 string_view synonym)
const
617 internal->add_synonym(
term, synonym);
622 string_view synonym)
const
624 internal->remove_synonym(
term, synonym);
630 internal->clear_synonyms(
term);
636 if (
rare(key.empty()))
639 internal->set_metadata(key, value);
645 string desc =
"WritableDatabase(";
646 desc +=
internal->get_description();
Calculate edit distances to a target string.
Empty database internals.
Sharded database backend.
void push_back(Xapian::Database::Internal *shard)
void reserve(size_type new_size)
Virtual base class for Database internals.
virtual size_type size() const
virtual TermList * open_term_list(docid did) const =0
bool is_read_only() const
Test if this shard is read-only.
virtual TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
virtual PositionList * open_position_list(docid did, std::string_view term) const =0
virtual TermList * open_spelling_termlist(std::string_view word) const
Create a termlist tree from trigrams of word.
virtual Document::Internal * open_document(docid did, bool lazy) const =0
Open a handle on a document.
virtual TermList * open_allterms(std::string_view prefix) const =0
virtual TermList * open_synonym_termlist(std::string_view term) const
Open a termlist returning synonyms 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 ValueList * open_value_list(valueno slot) const
Open a value stream.
An indexed database of documents.
Xapian::TermIterator metadata_keys_begin(std::string_view prefix={}) const
An iterator which returns all user-specified metadata keys.
Xapian::rev get_revision() const
Get the revision of the database.
ValueIterator valuestream_begin(Xapian::valueno slot) const
Return an iterator over the value in slot slot for each document.
Xapian::doccount get_termfreq(std::string_view term) const
Get the number of documents indexed by a specified term.
Database()
Construct a Database containing no shards.
Xapian::TermIterator synonym_keys_begin(std::string_view prefix={}) const
An iterator which returns all terms which have synonyms.
Xapian::termcount get_unique_terms_lower_bound() const
Get a lower bound on the unique terms size of a document in this DB.
void close()
Close the database.
double get_average_length() const
Get the mean document length in the database.
Xapian::totallength get_total_length() const
Get the total length of all the documents in the database.
Xapian::TermIterator spellings_begin() const
An iterator which returns all the spelling correction targets.
Xapian::WritableDatabase lock(int flags=0)
Lock a read-only database for writing.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
std::string reconstruct_text(Xapian::docid did, size_t length=0, std::string_view prefix={}, Xapian::termpos start_pos=0, Xapian::termpos end_pos=0) const
Reconstruct document text.
bool locked() const
Test if this database is currently locked for writing.
TermIterator termlist_begin(Xapian::docid did) const
Start iterating the terms in a document.
Xapian::termcount get_wdfdocmax(Xapian::docid did) const
Get the maximum wdf value in a specified document.
void keep_alive()
Send a keep-alive message.
virtual ~Database()
Destructor.
Xapian::termcount get_wdf_upper_bound(std::string_view term) const
Get an upper bound on the wdf of term term.
PositionIterator positionlist_begin(Xapian::docid did, std::string_view term) const
Start iterating positions for a term in a document.
size_t size() const
Return number of shards in this Database object.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
virtual std::string get_description() const
Return a string describing this object.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a specified document.
void add_database_(const Database &other, bool read_only)
bool term_exists(std::string_view term) const
Test is a particular term is present in any document.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
Xapian::termcount get_unique_terms_upper_bound() const
Get an upper bound on the unique terms size of a document in this DB.
bool has_positions() const
Does this database have any positional information?
Xapian::termcount get_collection_freq(std::string_view term) const
Get the total number of occurrences of a specified term.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
TermIterator allterms_begin(std::string_view prefix={}) const
Start iterating all terms in the database with a given prefix.
Database & operator=(const Database &o)
Assignment operator.
Xapian::TermIterator synonyms_begin(std::string_view term) const
An iterator which returns all the synonyms for a given term.
bool reopen()
Reopen the database at the latest available revision.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
std::string get_spelling_suggestion(std::string_view word, unsigned max_edit_distance=2) const
Suggest a spelling correction.
Xapian::Document get_document(Xapian::docid did, unsigned flags=0) const
Get a document from the database.
Xapian::Database unlock()
Release a database write lock.
std::string get_uuid() const
Get the UUID for the database.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
std::string get_metadata(std::string_view key) const
Get the user-specified metadata associated with a given key.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in a specified document.
Class representing a document.
Abstract base class for postlists.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Class for iterating over term positions.
Class for iterating over a list of terms.
Abstract base class for termlists.
virtual Internal * next()=0
Advance the current position to the next term in the termlist.
Class for iterating over a list of terms.
Class for iterating over document values.
This class provides read/write access to a database.
void delete_document(Xapian::docid did)
Delete a document from the database.
void clear_synonyms(std::string_view term) const
Remove all synonyms for a term.
void begin_transaction(bool flushed=true)
Begin a transaction.
void add_synonym(std::string_view term, std::string_view synonym) const
Add a synonym for a term.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a document in the database.
void set_metadata(std::string_view key, std::string_view metadata)
Set the user-specified metadata associated with a given key.
void end_transaction_(bool do_commit)
void add_spelling(std::string_view word, Xapian::termcount freqinc=1) const
Add a word to the spelling dictionary.
termcount remove_spelling(std::string_view word, termcount freqdec=1) const
Remove a word from the spelling dictionary.
std::string get_description() const
Return a string describing this object.
void commit()
Commit pending modifications.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
void remove_synonym(std::string_view term, std::string_view synonym) const
Remove a synonym for a term.
Constants in the Xapian namespace.
static void docid_zero_invalid()
static void empty_term_invalid()
static void empty_metadata_key()
An indexed database of documents.
Virtual base class for Database internals.
Edit distance calculation algorithm.
Empty database internals.
Hierarchy of classes which Xapian can throw as exceptions.
Sharded database backend.
The Xapian namespace contains public interfaces for the Xapian library.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DOC_ASSUME_VALID
Assume document id is valid.
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.
Various assertion macros.
Class for iterating over term positions.
Class for iterating over a list of document ids.
Xapian::PostingIterator internals.
Class for iterating over a list of terms.
Unicode and UTF-8 related classes and functions.