|
xapian-core
2.0.0
|
An indexed database of documents. More...
#include <database.h>
Inheritance diagram for Xapian::Database:
Collaboration diagram for Xapian::Database:Classes | |
| class | Internal |
| Virtual base class for Database internals. More... | |
Public Member Functions | |
| void | add_database (const Database &other) |
| Add shards from another Database. More... | |
| size_t | size () const |
| Return number of shards in this Database object. More... | |
| Database () | |
| Construct a Database containing no shards. More... | |
| Database (std::string_view path, int flags=0) | |
| Open a Database. More... | |
| Database (int fd, int flags=0) | |
| Open a single-file Database. More... | |
| virtual | ~Database () |
| Destructor. More... | |
| Database (const Database &o) | |
| Copy constructor. More... | |
| Database & | operator= (const Database &o) |
| Assignment operator. More... | |
| Database (Database &&o) | |
| Move constructor. More... | |
| Database & | operator= (Database &&o) |
| Move assignment operator. More... | |
| bool | reopen () |
| Reopen the database at the latest available revision. More... | |
| void | close () |
| Close the database. More... | |
| virtual std::string | get_description () const |
| Return a string describing this object. More... | |
| PostingIterator | postlist_begin (std::string_view term) const |
| Start iterating the postings of a term. More... | |
| PostingIterator | postlist_end (std::string_view) const noexcept |
| End iterator corresponding to postlist_begin(). More... | |
| TermIterator | termlist_begin (Xapian::docid did) const |
| Start iterating the terms in a document. More... | |
| TermIterator | termlist_end (Xapian::docid) const noexcept |
| End iterator corresponding to termlist_begin(). More... | |
| bool | has_positions () const |
| Does this database have any positional information? More... | |
| PositionIterator | positionlist_begin (Xapian::docid did, std::string_view term) const |
| Start iterating positions for a term in a document. More... | |
| PositionIterator | positionlist_end (Xapian::docid, std::string_view) const noexcept |
| End iterator corresponding to positionlist_begin(). More... | |
| TermIterator | allterms_begin (std::string_view prefix={}) const |
| Start iterating all terms in the database with a given prefix. More... | |
| TermIterator | allterms_end (std::string_view={}) const noexcept |
| End iterator corresponding to allterms_begin(prefix). More... | |
| Xapian::doccount | get_doccount () const |
| Get the number of documents in the database. More... | |
| Xapian::docid | get_lastdocid () const |
| Get the highest document id which has been used in the database. More... | |
| double | get_average_length () const |
| Get the mean document length in the database. More... | |
| double | get_avlength () const |
| Old name for get_average_length() for backward compatibility. More... | |
| Xapian::totallength | get_total_length () const |
| Get the total length of all the documents in the database. More... | |
| Xapian::doccount | get_termfreq (std::string_view term) const |
| Get the number of documents indexed by a specified term. More... | |
| bool | term_exists (std::string_view term) const |
| Test is a particular term is present in any document. More... | |
| Xapian::termcount | get_collection_freq (std::string_view term) const |
| Get the total number of occurrences of a specified term. More... | |
| Xapian::doccount | get_value_freq (Xapian::valueno slot) const |
| Return the frequency of a given value slot. More... | |
| std::string | get_value_lower_bound (Xapian::valueno slot) const |
| Get a lower bound on the values stored in the given value slot. More... | |
| std::string | get_value_upper_bound (Xapian::valueno slot) const |
| Get an upper bound on the values stored in the given value slot. More... | |
| Xapian::termcount | get_doclength_lower_bound () const |
| Get a lower bound on the length of a document in this DB. More... | |
| Xapian::termcount | get_doclength_upper_bound () const |
| Get an upper bound on the length of a document in this DB. More... | |
| Xapian::termcount | get_wdf_upper_bound (std::string_view term) const |
| Get an upper bound on the wdf of term term. More... | |
| Xapian::termcount | get_unique_terms_lower_bound () const |
| Get a lower bound on the unique terms size of a document in this DB. More... | |
| Xapian::termcount | get_unique_terms_upper_bound () const |
| Get an upper bound on the unique terms size of a document in this DB. More... | |
| ValueIterator | valuestream_begin (Xapian::valueno slot) const |
| Return an iterator over the value in slot slot for each document. More... | |
| ValueIterator | valuestream_end (Xapian::valueno) const noexcept |
| Return end iterator corresponding to valuestream_begin(). More... | |
| Xapian::termcount | get_doclength (Xapian::docid did) const |
| Get the length of a specified document. More... | |
| Xapian::termcount | get_unique_terms (Xapian::docid did) const |
| Get the number of unique terms in a specified document. More... | |
| Xapian::termcount | get_wdfdocmax (Xapian::docid did) const |
| Get the maximum wdf value in a specified document. More... | |
| void | keep_alive () |
| Send a keep-alive message. More... | |
| Xapian::Document | get_document (Xapian::docid did, unsigned flags=0) const |
| Get a document from the database. More... | |
| std::string | get_spelling_suggestion (std::string_view word, unsigned max_edit_distance=2) const |
| Suggest a spelling correction. More... | |
| Xapian::TermIterator | spellings_begin () const |
| An iterator which returns all the spelling correction targets. More... | |
| Xapian::TermIterator | spellings_end () const noexcept |
| End iterator corresponding to spellings_begin(). More... | |
| Xapian::TermIterator | synonyms_begin (std::string_view term) const |
| An iterator which returns all the synonyms for a given term. More... | |
| Xapian::TermIterator | synonyms_end (std::string_view) const noexcept |
| End iterator corresponding to synonyms_begin(term). More... | |
| Xapian::TermIterator | synonym_keys_begin (std::string_view prefix={}) const |
| An iterator which returns all terms which have synonyms. More... | |
| Xapian::TermIterator | synonym_keys_end (std::string_view={}) const noexcept |
| End iterator corresponding to synonym_keys_begin(prefix). More... | |
| std::string | get_metadata (std::string_view key) const |
| Get the user-specified metadata associated with a given key. More... | |
| Xapian::TermIterator | metadata_keys_begin (std::string_view prefix={}) const |
| An iterator which returns all user-specified metadata keys. More... | |
| Xapian::TermIterator | metadata_keys_end (std::string_view={}) const noexcept |
| End iterator corresponding to metadata_keys_begin(). More... | |
| std::string | get_uuid () const |
| Get the UUID for the database. More... | |
| bool | locked () const |
| Test if this database is currently locked for writing. More... | |
| Xapian::WritableDatabase | lock (int flags=0) |
| Lock a read-only database for writing. More... | |
| Xapian::Database | unlock () |
| Release a database write lock. More... | |
| Xapian::rev | get_revision () const |
| Get the revision of the database. More... | |
| void | compact (std::string_view output, unsigned flags=0, int block_size=0) |
| Produce a compact version of this database. More... | |
| void | compact (int fd, unsigned flags=0, int block_size=0) |
| Produce a compact version of this database. More... | |
| void | compact (std::string_view output, unsigned flags, int block_size, Xapian::Compactor &compactor) |
| Produce a compact version of this database. More... | |
| void | compact (int fd, unsigned flags, int block_size, Xapian::Compactor &compactor) |
| Produce a compact version of this database. More... | |
| 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. More... | |
Static Public Member Functions | |
| static size_t | check (std::string_view path, int opts=0, std::ostream *out=NULL) |
| Check the integrity of a database or database table. More... | |
| static size_t | check (int fd, int opts=0, std::ostream *out=NULL) |
| Check the integrity of a single file database. More... | |
Private Member Functions | |
| void | compact_ (const std::string_view *output_ptr, int fd, unsigned flags, int block_size, Xapian::Compactor *compactor) const |
| void | add_database_ (const Database &other, bool read_only) |
| Database (Internal *internal) XAPIAN_NONNULL() | |
Static Private Member Functions | |
| static size_t | check_ (const std::string_view *path_ptr, int fd, int opts, std::ostream *out) |
Private Attributes | |
| Xapian::Internal::intrusive_ptr_nonnull< Internal > | internal |
An indexed database of documents.
A Database object contains zero or more shards, and operations are performed across these shards.
To perform a search on a Database, you need to use an Enquire object.
Most methods can throw:
| Xapian::DatabaseCorruptError | if database corruption is detected |
| Xapian::DatabaseError | in various situation (for example, if there's an I/O error). |
| Xapian::DatabaseModifiedError | if the revision being read has been discarded |
| Xapian::DatabaseClosedError | may be thrown by some methods after after close() has been called |
| Xapian::NetworkError | when remote databases are in use |
Definition at line 75 of file database.h.
| Xapian::Database::Database | ( | ) |
Construct a Database containing no shards.
You can then add shards by calling add_database(). A Database containing no shards can also be useful in situations where you need an empty database.
Definition at line 83 of file database.cc.
|
explicit |
Open a Database.
| path | Filing system path to open database from |
| flags | Bitwise-or of Xapian::DB_* constants |
The path can be a file (for a stub database or a single-file glass database) or a directory (for a standard glass database). If flags includes DB_BACKEND_INMEMORY then path is ignored.
| Xapian::DatabaseOpeningError | if the specified database cannot be opened |
| Xapian::DatabaseVersionError | if the specified database has a format too old or too new to be supported. |
Definition at line 157 of file dbfactory.cc.
References BACKEND_GLASS, BACKEND_HONEY, Xapian::DB_BACKEND_GLASS, Xapian::DB_BACKEND_HONEY, Xapian::DB_BACKEND_INMEMORY, Xapian::DB_BACKEND_STUB, file_exists(), LOGCALL_CTOR, Xapian::open_stub(), rare, S_ISDIR, S_ISREG, test_if_single_file_db(), and usual.
|
explicit |
Open a single-file Database.
This method opens a single-file Database given a file descriptor open on it. Xapian looks starting at the current file offset, allowing a single file database to be easily embedded within another file.
| fd | File descriptor for the file. Xapian takes ownership of this and will close it when the database is closed. |
| flags | Bitwise-or of Xapian::DB_* constants. |
| Xapian::DatabaseOpeningError | if the specified database cannot be opened |
| Xapian::DatabaseVersionError | if the specified database has a format too old or too new to be supported. |
Definition at line 329 of file dbfactory.cc.
References LOGCALL_CTOR.
|
explicitprivate |
Wrap an existing Internal.
Definition at line 68 of file database.cc.
|
virtual |
Destructor.
Definition at line 88 of file database.cc.
|
default |
Copy constructor.
The internals are reference counted, so copying is cheap.
|
default |
Move constructor.
|
inline |
Add shards from another Database.
Any shards in other are appended to the list of shards in this object. The shards are reference counted and also remain in other.
| other | Another Database to add shards from |
| Xapian::InvalidArgumentError | if other is the same object as this. |
Definition at line 109 of file database.h.
Referenced by DEFINE_TESTCASE(), BackendManagerMulti::get_remote_database(), main(), Xapian::open_stub(), and RemoteServer::RemoteServer().
|
private |
Implementation behind public add_database() methods.
Definition at line 111 of file database.cc.
References Xapian::Internal::intrusive_ptr_nonnull< T >::get(), internal, Xapian::Database::Internal::is_read_only(), MultiDatabase::push_back(), MultiDatabase::reserve(), and Xapian::Database::Internal::size().
| TermIterator Xapian::Database::allterms_begin | ( | std::string_view | prefix = {} | ) | const |
Start iterating all terms in the database with a given prefix.
The terms are returned in ascending string order (by byte value).
| prefix | The prefix to restrict the returned terms to (default: iterate all terms) |
Definition at line 209 of file database.cc.
References internal, and Xapian::Database::Internal::open_allterms().
Referenced by check_equal_dbs(), check_sparse_uid_terms(), dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), RemoteServer::msg_allterms(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), show_db_stats(), and show_termlist().
|
inlinenoexcept |
End iterator corresponding to allterms_begin(prefix).
Definition at line 307 of file database.h.
Referenced by check_equal_dbs(), check_sparse_uid_terms(), dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), RemoteServer::msg_allterms(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), show_db_stats(), and show_termlist().
|
inlinestatic |
Check the integrity of a single file database.
| fd | file descriptor for the database. The current file offset is used, allowing checking a single file database which is embedded within another file. Xapian takes ownership of the file descriptor and will close it before returning. |
| opts | Options to use for check |
| out | std::ostream to write output to (NULL for no output) |
Definition at line 685 of file database.h.
References opts.
|
inlinestatic |
Check the integrity of a database or database table.
| path | Path to database or table |
| opts | Options to use for check |
| out | std::ostream to write output to (NULL for no output) |
Definition at line 669 of file database.h.
References opts.
Referenced by DEFINE_TESTCASE(), and main().
|
staticprivate |
Implementation behind check() static methods.
Definition at line 450 of file dbcheck.cc.
References BACKEND_GLASS, BACKEND_HONEY, BACKEND_OLD, BACKEND_UNKNOWN, check_db_dir(), check_db_fd(), check_db_table(), Xapian::check_stub(), Xapian::DBCHECK_FIX, endswith(), GLASS_TABLE_EXTENSION, HONEY_TABLE_EXTENSION, opts, S_ISDIR, S_ISREG, test_if_single_file_db(), and throw_no_db_to_check().
| void Xapian::Database::close | ( | ) |
Close the database.
This closes the database and closes all its file handles.
For a WritableDatabase, if a transaction is active it will be aborted, while if no transaction is active commit() will be implicitly called. Also the write lock is released.
Calling close() on an object cannot be undone - in particular, a subsequent call to reopen() on the same object will not reopen it, but will instead throw a Xapian::DatabaseClosedError exception.
Calling close() again on an object which has already been closed has no effect (and doesn't raise an exception).
After close() has been called, calls to other methods of the database, and to methods of other objects associated with the database, will either:
The reason for this behaviour is that otherwise we'd have to check that the database is still open on every method call on every object associated with a Database, when in many cases they are working on data which has already been loaded and so they are able to just behave correctly.
Definition at line 99 of file database.cc.
Referenced by BackendManagerMulti::createdb_multi(), DEFINE_TESTCASE(), BackendManagerGlass::do_get_database_path(), and BackendManagerHoney::do_get_database_path().
|
inline |
Produce a compact version of this database.
The compactor functor allows handling progress output and specifying how user metadata is merged.
This variant writes a single-file database to the specified file descriptor. Only the glass backend supports such databases, so this form is only supported for this backend.
| fd | File descriptor to write the compact version to. The descriptor needs to be readable and writable (open with O_RDWR) and seekable. The current file offset is used, allowing compacting to a single file database embedded within another file. Xapian takes ownership of the file descriptor and will close it before returning. |
| flags | Any of the following combined using bitwise-or (| in C++):
|
| block_size | This specifies the block size (in bytes) for to use for the output. For glass, the block size must be a power of 2 between 2048 and 65536 (inclusive), and the default (also used if an invalid value is passed) is 8192 bytes. |
| compactor | Functor |
Definition at line 911 of file database.h.
|
inline |
Produce a compact version of this database.
This variant writes a single-file database to the specified file descriptor. Only the glass backend supports such databases, so this form is only supported for this backend.
| fd | File descriptor to write the compact version to. The descriptor needs to be readable and writable (open with O_RDWR) and seekable. The current file offset is used, allowing compacting to a single file database embedded within another file. Xapian takes ownership of the file descriptor and will close it before returning. |
| flags | Any of the following combined using bitwise-or (| in C++):
|
| block_size | This specifies the block size (in bytes) for to use for the output. For glass, the block size must be a power of 2 between 2048 and 65536 (inclusive), and the default (also used if an invalid value is passed) is 8192 bytes. |
Definition at line 793 of file database.h.
|
inline |
Produce a compact version of this database.
The compactor functor allows handling progress output and specifying how user metadata is merged.
| output | Path to write the compact version to. This can be the same as an input if that input is a stub database (in which case the database(s) listed in the stub will be compacted to a new database and then the stub will be atomically updated to point to this new database). |
| flags | Any of the following combined using bitwise-or (| in C++):
|
| block_size | This specifies the block size (in bytes) for to use for the output. For glass, the block size must be a power of 2 between 2048 and 65536 (inclusive), and the default (also used if an invalid value is passed) is 8192 bytes. |
| compactor | Functor |
Definition at line 849 of file database.h.
|
inline |
Produce a compact version of this database.
| output | Path to write the compact version to. This can be the same as an input if that input is a stub database (in which case the database(s) listed in the stub will be compacted to a new database and then the stub will be atomically updated to point to this new database). |
| flags | Any of the following combined using bitwise-or (| in C++):
|
| block_size | This specifies the block size (in bytes) for to use for the output. For glass, the block size must be a power of 2 between 2048 and 65536 (inclusive), and the default (also used if an invalid value is passed) is 8192 bytes. |
Definition at line 738 of file database.h.
Referenced by DEFINE_TESTCASE(), BackendManagerHoney::do_get_database_path(), BackendManagerSingleFile::do_get_database_path(), BackendManagerHoney::finalise_generated_database(), BackendManagerSingleFile::finalise_generated_database(), and main().
|
private |
Implementation behind public compact() methods.
Definition at line 126 of file compactor.cc.
References Assert, AssertEq, AssertRel, Xapian::Internal::PostList::at_end(), BACKEND_GLASS, BACKEND_HONEY, backend_mismatch(), BACKEND_UNKNOWN, GlassDatabase::compact(), HoneyDatabase::compact(), Xapian::DB_BACKEND_GLASS, Xapian::DB_BACKEND_HONEY, Xapian::DBCOMPACT_NO_RENUMBER, Xapian::DBCOMPACT_SINGLE_FILE, dir_exists(), DIR_SEPS, file_exists(), Xapian::Compactor::FULL, Xapian::Compactor::FULLER, Xapian::Internal::PostList::get_docid(), io_tmp_rename(), LOGCALL_VOID, Xapian::Internal::PostList::next(), RealTime::now(), p, MultiDatabase::push_back(), Xapian::Internal::PostList::skip_to(), Heap::sort(), srcdir, Xapian::Compactor::STANDARD, Xapian::Internal::str(), and UNSIGNED_OVERFLOW_OK.
| double Xapian::Database::get_average_length | ( | ) | const |
Get the mean document length in the database.
Definition at line 245 of file database.cc.
References rare.
|
inline |
Old name for get_average_length() for backward compatibility.
Definition at line 322 of file database.h.
Referenced by dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), and show_db_stats().
| Xapian::termcount Xapian::Database::get_collection_freq | ( | std::string_view | term | ) | const |
Get the total number of occurrences of a specified term.
The collection frequency of a term is defined as the total number of times it occurs in the database, which is the sum of its wdf in all the documents it indexes.
| term | The term to get the collection frequency of. An empty string acts as a special pseudo-term which indexes all the documents in the database, so returns get_doccount(). If the term isn't present in the database, 0 is returned. |
Definition at line 273 of file database.cc.
References get_doccount(), and term.
Referenced by dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), main(), RemoteServer::msg_collfreq(), RemoteServer::msg_freqs(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), show_termlist(), termstats_to_string(), test_emptyterm1_helper(), and test_emptyterm2_helper().
|
virtual |
Return a string describing this object.
Reimplemented in Xapian::WritableDatabase.
Definition at line 391 of file database.cc.
Referenced by DEFINE_TESTCASE().
| Xapian::doccount Xapian::Database::get_doccount | ( | ) | const |
Get the number of documents in the database.
Definition at line 233 of file database.cc.
Referenced by check_equal_dbs(), check_vals(), dbcheck(), DEFINE_TESTCASE(), get_collection_freq(), CheckStatsWeight::get_sumpart(), get_termfreq(), main(), RemoteServer::msg_update(), Xapian::FixedWeightPostingSource::reset(), MyDontAskWeightPostingSource::reset(), show_db_stats(), test_emptyterm1_helper(), and test_emptyterm2_helper().
| Xapian::termcount Xapian::Database::get_doclength | ( | Xapian::docid | did | ) | const |
Get the length of a specified document.
| did | The document id of the document |
Xapian defines a document's length as the sum of the wdf of all the terms which index it.
Definition at line 341 of file database.cc.
References docid_zero_invalid().
Referenced by dbcheck(), DEFINE_TESTCASE(), docstats_to_string(), Xapian::PostingIterator::Internal::get_doclength(), CheckStatsWeight5::get_sumpart(), RemoteServer::msg_doclength(), RemoteServer::msg_termlist(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
| Xapian::termcount Xapian::Database::get_doclength_lower_bound | ( | ) | const |
Get a lower bound on the length of a document in this DB.
This bound does not include any zero-length documents.
Definition at line 302 of file database.cc.
Referenced by dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), RemoteServer::msg_update(), CheckBoundsPostingSource::reset(), and show_db_stats().
| Xapian::termcount Xapian::Database::get_doclength_upper_bound | ( | ) | const |
Get an upper bound on the length of a document in this DB.
Definition at line 308 of file database.cc.
Referenced by dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), RemoteServer::msg_update(), CheckBoundsPostingSource::reset(), and show_db_stats().
| Document Xapian::Database::get_document | ( | Xapian::docid | did, |
| unsigned | flags = 0 |
||
| ) | const |
Get a document from the database.
The returned object acts as a handle which lazily fetches information about the specified document from the database.
| did | The document ID of the document to be get |
| flags | Zero or more flags bitwise-or-ed together (currently only Xapian::DOC_ASSUME_VALID is supported). (default: 0) |
| Xapian::InvalidArgumentError | is thrown if did is 0. |
| Xapian::DocNotFoundError | is thrown if the specified docid is not present in this database. |
Definition at line 368 of file database.cc.
References Xapian::DOC_ASSUME_VALID, docid_zero_invalid(), internal, Xapian::Database::Internal::open_document(), and rare.
Referenced by check_vals(), dbcheck(), DEFINE_TESTCASE(), Xapian::Enquire::Internal::get_document(), main(), make_orcheck_db(), RemoteServer::msg_document(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), show_docdata(), show_value(), and show_values().
| Xapian::docid Xapian::Database::get_lastdocid | ( | ) | const |
Get the highest document id which has been used in the database.
Definition at line 239 of file database.cc.
Referenced by check_equal_dbs(), check_vals(), dbcheck(), DEFINE_TESTCASE(), RemoteServer::msg_update(), OnlyTheFirstPostingSource::reset(), MyDontAskWeightPostingSource::reset(), and show_db_stats().
| string Xapian::Database::get_metadata | ( | std::string_view | key | ) | const |
Get the user-specified metadata associated with a given key.
User-specified metadata allows you to store arbitrary information in the form of (key, value) pairs. See WritableDatabase::set_metadata() for more information.
When invoked on a Xapian::Database object representing multiple databases, currently only the metadata for the first is considered but this behaviour may change in the future.
If there is no piece of metadata associated with the specified key, an empty string is returned (this applies even for backends which don't support metadata).
Empty keys are not valid, and specifying one will cause an exception.
| key | The key of the metadata item to access. |
| Xapian::InvalidArgumentError | will be thrown if the key supplied is empty. |
Definition at line 490 of file database.cc.
References empty_metadata_key(), and rare.
Referenced by DEFINE_TESTCASE(), main(), and RemoteServer::msg_getmetadata().
| Xapian::rev Xapian::Database::get_revision | ( | ) | const |
Get the revision of the database.
The revision is an unsigned integer which increases with each commit.
| Xapian::InvalidOperationError | If the database consists of more than one shard. |
| Xapian::UnimplementedError | Currently this is only implemented for glass. |
| In | Xapian < 1.4.13, if the database consists of no shards; In Xapian >= 1.4.13 this method returns 0 if there are no shards. |
Experimental - see https://xapian.org/docs/deprecation#experimental-features
Definition at line 527 of file database.cc.
Referenced by DEFINE_TESTCASE(), and show_db_stats().
| string Xapian::Database::get_spelling_suggestion | ( | std::string_view | word, |
| unsigned | max_edit_distance = 2 |
||
| ) | const |
Suggest a spelling correction.
| word | The potentially misspelled word. |
| max_edit_distance | Only consider words which are at most max_edit_distance edits from word. An edit is a character insertion, deletion, or the transposition of two adjacent characters (default is 2). |
Definition at line 400 of file database.cc.
References internal, LOGLINE, LOGVALUE, Xapian::TermIterator::Internal::next(), Xapian::Database::Internal::open_spelling_termlist(), rare, Glass::SPELLING, and term.
Referenced by DEFINE_TESTCASE().
| Xapian::doccount Xapian::Database::get_termfreq | ( | std::string_view | term | ) | const |
Get the number of documents indexed by a specified term.
| term | The term to get the frequency of. An empty string acts as a special pseudo-term which indexes all the documents in the database, so returns get_doccount(). If the term isn't present in the database, 0 is returned. |
Definition at line 262 of file database.cc.
References get_doccount(), and term.
Referenced by dbcheck(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), Xapian::Enquire::Internal::get_termfreq(), main(), RemoteServer::msg_freqs(), RemoteServer::msg_postlist(), RemoteServer::msg_termfreq(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), termstats_to_string(), test_emptyterm1_helper(), and test_emptyterm2_helper().
| Xapian::totallength Xapian::Database::get_total_length | ( | ) | const |
Get the total length of all the documents in the database.
Definition at line 256 of file database.cc.
Referenced by DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), RemoteServer::msg_update(), and show_db_stats().
| Xapian::termcount Xapian::Database::get_unique_terms | ( | Xapian::docid | did | ) | const |
Get the number of unique terms in a specified document.
| did | The document id of the document |
This is the number of different terms which index the given document.
Definition at line 350 of file database.cc.
References docid_zero_invalid().
Referenced by dbcheck(), DEFINE_TESTCASE(), Xapian::PostingIterator::Internal::get_unique_terms(), RemoteServer::msg_uniqueterms(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
| Xapian::termcount Xapian::Database::get_unique_terms_lower_bound | ( | ) | const |
Get a lower bound on the unique terms size of a document in this DB.
Definition at line 323 of file database.cc.
Referenced by DEFINE_TESTCASE(), and CheckStatsWeight::get_sumpart().
| Xapian::termcount Xapian::Database::get_unique_terms_upper_bound | ( | ) | const |
Get an upper bound on the unique terms size of a document in this DB.
Definition at line 329 of file database.cc.
Referenced by DEFINE_TESTCASE(), and CheckStatsWeight::get_sumpart().
| string Xapian::Database::get_uuid | ( | ) | const |
Get the UUID for the database.
The UUID will persist for the lifetime of the database.
Replicas (eg, made with the replication protocol, or by copying all the database files) will have the same UUID. However, copies (made with copydatabase, or xapian-compact) will have different UUIDs.
If the backend does not support UUIDs or this database has no subdatabases, the UUID will be empty.
If this database has multiple sub-databases, the UUID string will contain the UUIDs of all the sub-databases separated by colons.
Definition at line 505 of file database.cc.
Referenced by check_equal_dbs(), DEFINE_TESTCASE(), RemoteServer::msg_update(), and show_db_stats().
| Xapian::doccount Xapian::Database::get_value_freq | ( | Xapian::valueno | slot | ) | const |
Return the frequency of a given value slot.
This is the number of documents which have a (non-empty) value stored in the slot.
| slot | The value slot to examine. |
Definition at line 284 of file database.cc.
Referenced by DEFINE_TESTCASE(), main(), RemoteServer::msg_valuestats(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
| string Xapian::Database::get_value_lower_bound | ( | Xapian::valueno | slot | ) | const |
Get a lower bound on the values stored in the given value slot.
If there are no values stored in the given value slot, this will return an empty string.
| slot | The value slot to examine. |
Definition at line 290 of file database.cc.
Referenced by dbcheck(), DEFINE_TESTCASE(), main(), RemoteServer::msg_valuestats(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
| string Xapian::Database::get_value_upper_bound | ( | Xapian::valueno | slot | ) | const |
Get an upper bound on the values stored in the given value slot.
If there are no values stored in the given value slot, this will return an empty string.
| slot | The value slot to examine. |
Definition at line 296 of file database.cc.
Referenced by dbcheck(), DEFINE_TESTCASE(), main(), RemoteServer::msg_valuestats(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), and Xapian::ValueWeightPostingSource::reset().
| Xapian::termcount Xapian::Database::get_wdf_upper_bound | ( | std::string_view | term | ) | const |
Get an upper bound on the wdf of term term.
Definition at line 314 of file database.cc.
References term.
Referenced by dbcheck(), DEFINE_TESTCASE(), main(), and show_termlist().
| Xapian::termcount Xapian::Database::get_wdfdocmax | ( | Xapian::docid | did | ) | const |
Get the maximum wdf value in a specified document.
| did | The document id of the document |
Definition at line 359 of file database.cc.
References docid_zero_invalid().
Referenced by Xapian::PostingIterator::Internal::get_wdfdocmax(), and RemoteServer::msg_wdfdocmax().
| bool Xapian::Database::has_positions | ( | ) | const |
Does this database have any positional information?
Definition at line 215 of file database.cc.
Referenced by DEFINE_TESTCASE(), RemoteServer::msg_update(), and show_db_stats().
| void Xapian::Database::keep_alive | ( | ) |
Send a keep-alive message.
For remote databases, this method sends a message to the server to reset the timeout timer. As well as preventing timeouts at the Xapian remote protocol level, this message will also avoid timeouts at lower levels.
For local databases, this method does nothing.
Definition at line 385 of file database.cc.
Referenced by DEFINE_TESTCASE(), and RemoteServer::msg_keepalive().
| Xapian::WritableDatabase Xapian::Database::lock | ( | int | flags = 0 | ) |
Lock a read-only database for writing.
If the database is actually already writable (i.e. a WritableDatabase via a Database reference) then the same database is returned (with its flags updated, so this provides an efficient way to modify flags on an open WritableDatabase).
Unlike unlock(), the object this is called on remains open.
| flags | The flags to use for the writable database. Flags which specify how to open the database are ignored (e.g. DB_CREATE_OR_OVERWRITE doesn't result in the database being wiped), and flags which specify the backend are also ignored as they are only relevant when creating a new database. |
Definition at line 517 of file database.cc.
References internal, and Xapian::Database::Internal::update_lock().
Referenced by DEFINE_TESTCASE(), and RemoteServer::msg_writeaccess().
| bool Xapian::Database::locked | ( | ) | const |
Test if this database is currently locked for writing.
If the underlying object is actually a WritableDatabase, always returns true unless close() has been called.
Otherwise tests if there's a writer holding the lock (or if we can't test for a lock without taking it on the current platform, throw Xapian::UnimplementedError). If there's an error while trying to test the lock, throws Xapian::DatabaseLockError.
For multi-databases, this tests each sub-database and returns true if any of them are locked.
Definition at line 511 of file database.cc.
Referenced by DEFINE_TESTCASE(), and show_db_stats().
| Xapian::TermIterator Xapian::Database::metadata_keys_begin | ( | std::string_view | prefix = {} | ) | const |
An iterator which returns all user-specified metadata keys.
When invoked on a Xapian::Database object representing multiple databases, currently only the metadata for the first is considered but this behaviour may change in the future.
If the backend doesn't support metadata, then this method returns an iterator which compares equal to that returned by metadata_keys_end().
| prefix | If non-empty, only keys with this prefix are returned. |
| Xapian::UnimplementedError | will be thrown if the backend implements user-specified metadata, but doesn't implement iterating its keys (currently this happens for the InMemory backend). |
Definition at line 499 of file database.cc.
References internal, and Xapian::Database::Internal::open_metadata_keylist().
Referenced by DEFINE_TESTCASE(), main(), and RemoteServer::msg_metadatakeylist().
|
inlinenoexcept |
End iterator corresponding to metadata_keys_begin().
Definition at line 576 of file database.h.
Referenced by DEFINE_TESTCASE(), main(), and RemoteServer::msg_metadatakeylist().
Assignment operator.
The internals are reference counted, so assignment is cheap.
Referenced by Xapian::WritableDatabase::operator=().
| PositionIterator Xapian::Database::positionlist_begin | ( | Xapian::docid | did, |
| std::string_view | term | ||
| ) | const |
Start iterating positions for a term in a document.
| did | The document id of the document |
| term | The term |
Definition at line 221 of file database.cc.
References docid_zero_invalid(), empty_term_invalid(), internal, Xapian::Database::Internal::open_position_list(), and term.
Referenced by DEFINE_TESTCASE(), main(), RemoteServer::msg_positionlist(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), test_emptyterm1_helper(), and test_emptyterm2_helper().
|
inlinenoexcept |
End iterator corresponding to positionlist_begin().
Definition at line 292 of file database.h.
Referenced by DEFINE_TESTCASE(), main(), RemoteServer::msg_positionlist(), closedb1_iterators::setup(), and remotefailure1_iterators::setup().
| PostingIterator Xapian::Database::postlist_begin | ( | std::string_view | term | ) | const |
Start iterating the postings of a term.
| term | The term to iterate the postings of. An empty string acts as a special pseudo-term which indexes all the documents in the database with a wdf of 1. |
Definition at line 192 of file database.cc.
References term.
Referenced by check_sparse_uid_terms(), dbcheck(), DEFINE_TESTCASE(), main(), RemoteServer::msg_postlist(), Xapian::FixedWeightPostingSource::next(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), postlist_to_string(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), show_db_stats(), and Xapian::FixedWeightPostingSource::skip_to().
|
inlinenoexcept |
End iterator corresponding to postlist_begin().
Definition at line 258 of file database.h.
Referenced by Xapian::FixedWeightPostingSource::at_end(), dbcheck(), DEFINE_TESTCASE(), main(), RemoteServer::msg_postlist(), Xapian::FixedWeightPostingSource::next(), postlist_to_string(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), show_db_stats(), and Xapian::FixedWeightPostingSource::skip_to().
| string Xapian::Database::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.
This uses term positional information to reconstruct the document text which was indexed. Reading the required positional information is potentially quite I/O intensive.
The reconstructed text will be missing punctuation and most capitalisation.
| did | The document id of the document to reconstruct |
| length | Number of bytes of text to aim for - note that slightly more may be returned (default: 0 meaning unlimited) |
| prefix | Term prefix to reconstruct (default: none) |
| start_pos | First position to reconstruct (default: 0) |
| end_pos | Last position to reconstruct (default: 0 meaning all) |
Definition at line 533 of file database.cc.
Referenced by DEFINE_TESTCASE(), main(), and RemoteServer::msg_reconstructtext().
| bool Xapian::Database::reopen | ( | ) |
Reopen the database at the latest available revision.
Xapian databases (at least with most backends) support versioning such that a Database object uses a snapshot of the database. However, write operations may cause this snapshot to be discarded, which can cause Xapian::DatabaseModifiedError to be thrown. You can recover from this situation by calling reopen() and restarting the search operation.
All shards are updated to the latest available revision. This should be a cheap operation if they're already at the latest revision, so if you're using the same Database object for many searches it's reasonable to call reopen() before each search.
| Xapian::DatabaseError | is thrown if close() has been called on any of the shards. |
Definition at line 93 of file database.cc.
Referenced by DEFINE_TESTCASE(), RemoteServer::msg_reopen(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
| size_t Xapian::Database::size | ( | ) | const |
Return number of shards in this Database object.
If you want the number of documents, see @ get_doccount().
Definition at line 105 of file database.cc.
Referenced by BackendManagerMulti::createdb_multi(), DEFINE_TESTCASE(), CheckStatsWeight::get_sumpart(), and show_db_stats().
| TermIterator Xapian::Database::spellings_begin | ( | ) | const |
An iterator which returns all the spelling correction targets.
This returns all the words which are considered as targets for the spelling correction algorithm. The frequency of each word is available as the term frequency of each entry in the returned iterator.
Definition at line 472 of file database.cc.
References internal, and Xapian::Database::Internal::open_spelling_wordlist().
Referenced by DEFINE_TESTCASE(), and main().
|
inlinenoexcept |
End iterator corresponding to spellings_begin().
Definition at line 503 of file database.h.
Referenced by DEFINE_TESTCASE(), and main().
| TermIterator Xapian::Database::synonym_keys_begin | ( | std::string_view | prefix = {} | ) | const |
An iterator which returns all terms which have synonyms.
| prefix | If non-empty, only terms with this prefix are returned. |
Definition at line 484 of file database.cc.
References internal, and Xapian::Database::Internal::open_synonym_keylist().
Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), main(), and RemoteServer::msg_synonymkeylist().
|
inlinenoexcept |
End iterator corresponding to synonym_keys_begin(prefix).
Definition at line 526 of file database.h.
Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), main(), and RemoteServer::msg_synonymkeylist().
| TermIterator Xapian::Database::synonyms_begin | ( | std::string_view | term | ) | const |
An iterator which returns all the synonyms for a given term.
| term | The term to return synonyms for. |
Definition at line 478 of file database.cc.
References internal, Xapian::Database::Internal::open_synonym_termlist(), and term.
Referenced by TermGroup::as_group(), Terms::as_synonym_phrase_query(), DEFINE_TESTCASE(), Term::get_query_with_synonyms(), main(), and RemoteServer::msg_synonymtermlist().
|
inlinenoexcept |
End iterator corresponding to synonyms_begin(term).
Definition at line 514 of file database.h.
Referenced by TermGroup::as_group(), Terms::as_synonym_phrase_query(), DEFINE_TESTCASE(), Term::get_query_with_synonyms(), main(), and RemoteServer::msg_synonymtermlist().
| bool Xapian::Database::term_exists | ( | std::string_view | term | ) | const |
Test is a particular term is present in any document.
| term | The term to test for. An empty string acts as a special pseudo-term which indexes all the documents in the database, so returns true if the database contains any documents. |
db.term_exists(t) gives the same answer as db.get_termfreq(t) != 0, but is typically more efficient.
Definition at line 378 of file database.cc.
References term.
Referenced by dbcheck(), DEFINE_TESTCASE(), RemoteServer::msg_termexists(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), test_emptyterm1_helper(), and test_emptyterm2_helper().
| TermIterator Xapian::Database::termlist_begin | ( | Xapian::docid | did | ) | const |
Start iterating the terms in a document.
| did | The document id to iterate terms from |
The terms are returned in ascending string order (by byte value).
Definition at line 200 of file database.cc.
References docid_zero_invalid(), internal, and Xapian::Database::Internal::open_term_list().
Referenced by dbcheck(), DEFINE_TESTCASE(), docterms_to_string(), main(), RemoteServer::msg_positionlistcount(), RemoteServer::msg_termlist(), closedb1_iterators::perform(), remotefailure1_iterators::perform(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), show_termlist(), and test_termlist3_helper().
|
inlinenoexcept |
End iterator corresponding to termlist_begin().
Definition at line 271 of file database.h.
Referenced by dbcheck(), DEFINE_TESTCASE(), docterms_to_string(), main(), RemoteServer::msg_positionlistcount(), RemoteServer::msg_termlist(), closedb1_iterators::setup(), remotefailure1_iterators::setup(), and show_termlist().
| Xapian::Database Xapian::Database::unlock | ( | ) |
Release a database write lock.
If called on a read-only database then the same database is returned.
If called on a writable database, the object this method was called on is closed.
Definition at line 522 of file database.cc.
References internal, and Xapian::Database::Internal::update_lock().
Referenced by DEFINE_TESTCASE().
| ValueIterator Xapian::Database::valuestream_begin | ( | Xapian::valueno | slot | ) | const |
Return an iterator over the value in slot slot for each document.
Definition at line 335 of file database.cc.
References internal, and Xapian::Database::Internal::open_value_list().
Referenced by dbcheck(), DEFINE_TESTCASE(), main(), closedb1_iterators::perform(), and remotefailure1_iterators::perform().
|
inlinenoexcept |
Return end iterator corresponding to valuestream_begin().
Definition at line 421 of file database.h.
Referenced by dbcheck(), DEFINE_TESTCASE(), Xapian::ValuePostingSource::done(), and main().
|
private |
Reference counted internals.
Definition at line 97 of file database.h.
Referenced by add_database_(), allterms_begin(), Xapian::build_termlist_tree(), get_document(), Matcher::get_mset(), get_spelling_suggestion(), BackendManagerRemoteTcp::kill_remote(), lock(), metadata_keys_begin(), RemoteServer::msg_requestdocument(), PostListTree::next(), Xapian::open_stub(), positionlist_begin(), Xapian::Enquire::Internal::request_document(), PostListTree::set_postlists(), spellings_begin(), synonym_keys_begin(), synonyms_begin(), termlist_begin(), unlock(), valuestream_begin(), and Xapian::DatabaseMaster::write_changesets_to_fd().