#include <inmemory_database.h>


Public Member Functions | |
| InMemoryDatabase () | |
| Create and open an in-memory database. | |
| ~InMemoryDatabase () | |
| void | reopen () |
| Reopen the database to the latest available revision. | |
| void | close () |
| Close the database. | |
| bool | is_closed () const |
| Xapian::doccount | get_doccount () const |
| Return the number of docs in this (sub) database. | |
| Xapian::docid | get_lastdocid () const |
| Return the last used document id of this (sub) database. | |
| totlen_t | get_total_length () const |
| Return the total length of all documents in this database. | |
| Xapian::doclength | get_avlength () const |
| Return the average length of a document in this (sub) database. | |
| Xapian::termcount | get_doclength (Xapian::docid did) const |
| Get the length of a given document. | |
| Xapian::doccount | get_termfreq (const string &tname) const |
| Return the number of documents indexed by a given term. | |
| Xapian::termcount | get_collection_freq (const string &tname) const |
| Return the total number of occurrences of the given term. | |
| Xapian::doccount | get_value_freq (Xapian::valueno slot) const |
| Return the frequency of a given value slot. | |
| std::string | get_value_lower_bound (Xapian::valueno slot) const |
| Get a lower bound on the values stored in the given value slot. | |
| std::string | get_value_upper_bound (Xapian::valueno slot) const |
| Get an upper bound on the values stored in the given value slot. | |
| bool | term_exists (const string &tname) const |
| Check whether a given term is in the database. | |
| bool | has_positions () const |
| Check whether this database contains any positional information. | |
| LeafPostList * | open_post_list (const string &tname) const |
| Open a posting list. | |
| TermList * | open_term_list (Xapian::docid did) const |
| Open a term list. | |
| Xapian::Document::Internal * | open_document (Xapian::docid did, bool lazy) const |
| Open a document. | |
| std::string | get_metadata (const std::string &key) const |
| Get the metadata associated with a given key. | |
| TermList * | open_metadata_keylist (const std::string &prefix) const |
| Open a termlist returning each metadata key. | |
| void | set_metadata (const std::string &key, const std::string &value) |
| Set the metadata associated with a given key. | |
| Xapian::termcount | positionlist_count (Xapian::docid did, const string &tname) const |
| PositionList * | open_position_list (Xapian::docid did, const string &tname) const |
| Open a position list for the given term in the given document. | |
| TermList * | open_allterms (const string &prefix) const |
| Open an allterms list. | |
| XAPIAN_NORETURN (static void throw_database_closed()) | |
Private Member Functions | |
| InMemoryDatabase & | operator= (const InMemoryDatabase &) |
| InMemoryDatabase (const InMemoryDatabase &) | |
| void | make_term (const string &tname) |
| bool | doc_exists (Xapian::docid did) const |
| Xapian::docid | make_doc (const string &docdata) |
| void | finish_add_doc (Xapian::docid did, const Xapian::Document &document) |
| void | add_values (Xapian::docid did, const map< Xapian::valueno, string > &values_) |
| void | make_posting (InMemoryDoc *doc, const string &tname, Xapian::docid did, Xapian::termpos position, Xapian::termcount wdf, bool use_position=true) |
| void | commit () |
| Implementation of virtual methods: see Database for details. | |
| void | cancel () |
| Implementation of virtual methods: see Database for details. | |
| Xapian::docid | add_document (const Xapian::Document &document) |
| Implementation of virtual methods: see Database for details. | |
| void | delete_document (Xapian::docid did) |
| Implementation of virtual methods: see Database for details. | |
| void | replace_document (Xapian::docid did, const Xapian::Document &document) |
| Implementation of virtual methods: see Database for details. | |
Private Attributes | |
| map< string, InMemoryTerm > | postlists |
| vector< InMemoryDoc > | termlists |
| vector< std::string > | doclists |
| vector< std::map < Xapian::valueno, string > > | valuelists |
| std::map< Xapian::valueno, ValueStats > | valuestats |
| vector< Xapian::termcount > | doclengths |
| std::map< string, string > | metadata |
| Xapian::doccount | totdocs |
| totlen_t | totlen |
| bool | positions_present |
| bool | closed |
Friends | |
| class | InMemoryAllDocsPostList |
| class | InMemoryDocument |
This is a prototype database, mainly used for debugging and testing.
Definition at line 239 of file inmemory_database.h.
| InMemoryDatabase::InMemoryDatabase | ( | const InMemoryDatabase & | ) | [private] |
| InMemoryDatabase::InMemoryDatabase | ( | ) |
Create and open an in-memory database.
| Xapian::DatabaseOpeningError | thrown if database can't be opened. |
Definition at line 384 of file inmemory_database.cc.
References postlists, Xapian::Database::Internal::transaction_state, and Xapian::Database::Internal::TRANSACTION_UNIMPLEMENTED.
| InMemoryDatabase::~InMemoryDatabase | ( | ) |
Definition at line 395 of file inmemory_database.cc.
References Xapian::Database::Internal::dtor_called().
| Xapian::docid InMemoryDatabase::add_document | ( | const Xapian::Document & | document | ) | [private, virtual] |
Implementation of virtual methods: see Database for details.
Reimplemented from Xapian::Database::Internal.
Definition at line 774 of file inmemory_database.cc.
References closed, finish_add_doc(), Xapian::Document::get_data(), LOGCALL, make_doc(), and RETURN.
| void InMemoryDatabase::add_values | ( | Xapian::docid | did, | |
| const map< Xapian::valueno, string > & | values_ | |||
| ) | [private] |
Definition at line 625 of file inmemory_database.cc.
References closed, valuelists, and valuestats.
Referenced by finish_add_doc().
| void InMemoryDatabase::cancel | ( | ) | [private, virtual] |
Implementation of virtual methods: see Database for details.
Reimplemented from Xapian::Database::Internal.
Definition at line 666 of file inmemory_database.cc.
| void InMemoryDatabase::close | ( | ) | [virtual] |
Close the database.
Implements Xapian::Database::Internal.
Definition at line 407 of file inmemory_database.cc.
References closed, doclengths, doclists, metadata, postlists, termlists, valuelists, and valuestats.
| void InMemoryDatabase::commit | ( | ) | [private, virtual] |
Implementation of virtual methods: see Database for details.
Reimplemented from Xapian::Database::Internal.
Definition at line 660 of file inmemory_database.cc.
| void InMemoryDatabase::delete_document | ( | Xapian::docid | did | ) | [private, virtual] |
Implementation of virtual methods: see Database for details.
Reimplemented from Xapian::Database::Internal.
Definition at line 671 of file inmemory_database.cc.
References Assert, closed, doc_exists(), doclengths, doclists, positions_present, postlists, Xapian::Internal::str(), termlists, totdocs, totlen, valuelists, and valuestats.
| bool InMemoryDatabase::doc_exists | ( | Xapian::docid | did | ) | const [private] |
Definition at line 439 of file inmemory_database.cc.
References closed, and termlists.
Referenced by delete_document(), get_doclength(), make_posting(), open_document(), open_position_list(), open_term_list(), positionlist_count(), and replace_document().
| void InMemoryDatabase::finish_add_doc | ( | Xapian::docid | did, | |
| const Xapian::Document & | document | |||
| ) | [private] |
Definition at line 787 of file inmemory_database.cc.
References add_values(), Assert, doclengths, Xapian::ValueIterator::get_valueno(), Xapian::TermIterator::get_wdf(), LOGLINE, make_posting(), make_term(), Xapian::TermIterator::positionlist_begin(), Xapian::TermIterator::positionlist_end(), positions_present, postlists, Xapian::Document::termlist_begin(), Xapian::Document::termlist_end(), termlists, totdocs, totlen, Xapian::Document::values_begin(), and Xapian::Document::values_end().
Referenced by add_document(), and replace_document().
| Xapian::doclength InMemoryDatabase::get_avlength | ( | ) | const [virtual] |
Return the average length of a document in this (sub) database.
See Database::Internal::get_doclength() for the meaning of document length within Xapian.
Implements Xapian::Database::Internal.
Definition at line 511 of file inmemory_database.cc.
| Xapian::termcount InMemoryDatabase::get_collection_freq | ( | const string & | tname | ) | const [virtual] |
Return the total number of occurrences of the given term.
This is the sum of the number of occurrences of the term in each document: ie, the sum of the within document frequencies of the term.
| tname | The term whose collection frequency is being requested. |
Implements Xapian::Database::Internal.
Definition at line 455 of file inmemory_database.cc.
| Xapian::doccount InMemoryDatabase::get_doccount | ( | ) | const [virtual] |
Return the number of docs in this (sub) database.
Implements Xapian::Database::Internal.
Definition at line 491 of file inmemory_database.cc.
| Xapian::termcount InMemoryDatabase::get_doclength | ( | Xapian::docid | did | ) | const [virtual] |
Get the length of a given document.
Document length, for the purposes of Xapian, is defined to be the number of instances of terms within a document. Expressed differently, the sum of the within document frequencies over all the terms in the document.
| did | The document id of the document whose length is being requested. |
Implements Xapian::Database::Internal.
Definition at line 519 of file inmemory_database.cc.
References closed, doc_exists(), doclengths, and Xapian::Internal::str().
| Xapian::docid InMemoryDatabase::get_lastdocid | ( | ) | const [virtual] |
Return the last used document id of this (sub) database.
Implements Xapian::Database::Internal.
Definition at line 498 of file inmemory_database.cc.
| std::string InMemoryDatabase::get_metadata | ( | const std::string & | key | ) | const [virtual] |
Get the metadata associated with a given key.
See Database::get_metadata() for more information.
Reimplemented from Xapian::Database::Internal.
Definition at line 558 of file inmemory_database.cc.
| Xapian::doccount InMemoryDatabase::get_termfreq | ( | const string & | tname | ) | const [virtual] |
Return the number of documents indexed by a given term.
This may be an approximation, but must be an upper bound (ie, greater or equal to the true value), and should be as accurate as possible.
| tname | The term whose term frequency is being requested. |
Implements Xapian::Database::Internal.
Definition at line 446 of file inmemory_database.cc.
| totlen_t InMemoryDatabase::get_total_length | ( | ) | const [virtual] |
Return the total length of all documents in this database.
Implements Xapian::Database::Internal.
Definition at line 505 of file inmemory_database.cc.
References totlen.
| Xapian::doccount InMemoryDatabase::get_value_freq | ( | Xapian::valueno | slot | ) | const [virtual] |
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. |
| UnimplementedError | The frequency of the value isn't available for this database type. |
Reimplemented from Xapian::Database::Internal.
Definition at line 464 of file inmemory_database.cc.
References closed, and valuestats.
| std::string InMemoryDatabase::get_value_lower_bound | ( | Xapian::valueno | slot | ) | const [virtual] |
Get a lower bound on the values stored in the given value slot.
If the lower bound isn't available for the given database type, this will return the lowest possible bound - the empty string.
| slot | The value slot to examine. |
Reimplemented from Xapian::Database::Internal.
Definition at line 473 of file inmemory_database.cc.
References closed, and valuestats.
| std::string InMemoryDatabase::get_value_upper_bound | ( | Xapian::valueno | slot | ) | const [virtual] |
Get an upper bound on the values stored in the given value slot.
| slot | The value slot to examine. |
| UnimplementedError | The upper bound of the values isn't available for this database type. |
Reimplemented from Xapian::Database::Internal.
Definition at line 482 of file inmemory_database.cc.
References closed, and valuestats.
| bool InMemoryDatabase::has_positions | ( | ) | const [virtual] |
Check whether this database contains any positional information.
Implements Xapian::Database::Internal.
Definition at line 897 of file inmemory_database.cc.
References closed, and positions_present.
| bool InMemoryDatabase::is_closed | ( | ) | const [inline] |
| Xapian::docid InMemoryDatabase::make_doc | ( | const string & | docdata | ) | [private] |
Definition at line 838 of file inmemory_database.cc.
References AssertEqParanoid, doclengths, doclists, and termlists.
Referenced by add_document().
| void InMemoryDatabase::make_posting | ( | InMemoryDoc * | doc, | |
| const string & | tname, | |||
| Xapian::docid | did, | |||
| Xapian::termpos | position, | |||
| Xapian::termcount | wdf, | |||
| bool | use_position = true | |||
| ) | [private] |
Definition at line 849 of file inmemory_database.cc.
References InMemoryDoc::add_posting(), Assert, InMemoryPosting::did, doc_exists(), doclengths, InMemoryTermEntry::positions, InMemoryPosting::positions, postlists, termlists, InMemoryTermEntry::tname, InMemoryPosting::valid, InMemoryTermEntry::wdf, and InMemoryPosting::wdf.
Referenced by finish_add_doc().
| void InMemoryDatabase::make_term | ( | const string & | tname | ) | [private] |
Definition at line 832 of file inmemory_database.cc.
References postlists.
Referenced by finish_add_doc().
| TermList * InMemoryDatabase::open_allterms | ( | const string & | prefix | ) | const [virtual] |
Open an allterms list.
This is a list of all the terms in the database
| prefix | The prefix to restrict the terms to. |
Implements Xapian::Database::Internal.
Definition at line 904 of file inmemory_database.cc.
| Xapian::Document::Internal * InMemoryDatabase::open_document | ( | Xapian::docid | did, | |
| bool | lazy | |||
| ) | const [virtual] |
Open a document.
This is used to access the values and data associated with a document. See class Xapian::Document::Internal for further details.
| did | The document id which is being requested. | |
| lazy | No need to check that this document actually exists. Used when we already know that this document exists (only a hint - the backend may still check). |
Implements Xapian::Database::Internal.
Definition at line 544 of file inmemory_database.cc.
References Assert, closed, doc_exists(), InMemoryDocument, and Xapian::Internal::str().
| TermList * InMemoryDatabase::open_metadata_keylist | ( | const std::string & | prefix | ) | const [virtual] |
Open a termlist returning each metadata key.
Only metadata keys which are associated with a non-empty value will be returned.
| prefix | If non-empty, only keys with this prefix are returned. |
Reimplemented from Xapian::Database::Internal.
Definition at line 568 of file inmemory_database.cc.
References metadata.
| PositionList * InMemoryDatabase::open_position_list | ( | Xapian::docid | did, | |
| const string & | tname | |||
| ) | const [virtual] |
Open a position list for the given term in the given document.
| did | The document id for which a position list is being requested. | |
| tname | The term for which a position list is being requested. |
Implements Xapian::Database::Internal.
Definition at line 607 of file inmemory_database.cc.
References closed, doc_exists(), termlists, InMemoryDoc::terms, and usual.
| LeafPostList * InMemoryDatabase::open_post_list | ( | const string & | tname | ) | const [virtual] |
Open a posting list.
Method defined by subclass to open a posting list. This is a list of all the documents which contain a given term.
| tname | The term whose posting list is being requested. |
Implements Xapian::Database::Internal.
Definition at line 421 of file inmemory_database.cc.
References Assert, closed, InMemoryAllDocsPostList, and postlists.
| TermList * InMemoryDatabase::open_term_list | ( | Xapian::docid | did | ) | const [virtual] |
Open a term list.
This is a list of all the terms contained by a given document.
| did | The document id whose term list is being requested. |
Implements Xapian::Database::Internal.
Definition at line 530 of file inmemory_database.cc.
References Assert, closed, doc_exists(), doclengths, Xapian::Internal::str(), and termlists.
| InMemoryDatabase& InMemoryDatabase::operator= | ( | const InMemoryDatabase & | ) | [private] |
| Xapian::termcount InMemoryDatabase::positionlist_count | ( | Xapian::docid | did, | |
| const string & | tname | |||
| ) | const |
Definition at line 588 of file inmemory_database.cc.
References closed, doc_exists(), termlists, and InMemoryDoc::terms.
| void InMemoryDatabase::reopen | ( | ) | [virtual] |
Reopen the database to the latest available revision.
Database backends which don't support simultaneous update and reading probably don't need to do anything here.
Reimplemented from Xapian::Database::Internal.
Definition at line 401 of file inmemory_database.cc.
References closed.
| void InMemoryDatabase::replace_document | ( | Xapian::docid | did, | |
| const Xapian::Document & | document | |||
| ) | [private, virtual] |
Implementation of virtual methods: see Database for details.
Reimplemented from Xapian::Database::Internal.
Definition at line 719 of file inmemory_database.cc.
References Assert, closed, doc_exists(), doclengths, doclists, finish_add_doc(), Xapian::Document::get_data(), LOGCALL_VOID, postlists, termlists, totdocs, totlen, valuelists, and valuestats.
| void InMemoryDatabase::set_metadata | ( | const std::string & | key, | |
| const std::string & | value | |||
| ) | [virtual] |
Set the metadata associated with a given key.
See WritableDatabase::set_metadata() for more information.
Reimplemented from Xapian::Database::Internal.
Definition at line 576 of file inmemory_database.cc.
| bool InMemoryDatabase::term_exists | ( | const string & | tname | ) | const [virtual] |
Check whether a given term is in the database.
| tname | The term whose presence is being checked. |
Implements Xapian::Database::Internal.
Definition at line 887 of file inmemory_database.cc.
| InMemoryDatabase::XAPIAN_NORETURN | ( | static void | throw_database_closed() | ) |
friend class InMemoryAllDocsPostList [friend] |
friend class InMemoryDocument [friend] |
bool InMemoryDatabase::closed [private] |
Definition at line 260 of file inmemory_database.h.
Referenced by add_document(), add_values(), close(), delete_document(), InMemoryDocument::do_get_data(), doc_exists(), get_avlength(), get_collection_freq(), get_doccount(), get_doclength(), get_lastdocid(), get_metadata(), get_termfreq(), get_value_freq(), get_value_lower_bound(), get_value_upper_bound(), has_positions(), is_closed(), open_allterms(), open_document(), open_position_list(), open_post_list(), open_term_list(), positionlist_count(), reopen(), replace_document(), set_metadata(), and term_exists().
vector<Xapian::termcount> InMemoryDatabase::doclengths [private] |
Definition at line 249 of file inmemory_database.h.
Referenced by close(), delete_document(), finish_add_doc(), get_doclength(), make_doc(), make_posting(), open_term_list(), and replace_document().
vector<std::string> InMemoryDatabase::doclists [private] |
Definition at line 245 of file inmemory_database.h.
Referenced by close(), delete_document(), InMemoryDocument::do_get_data(), make_doc(), and replace_document().
std::map<string, string> InMemoryDatabase::metadata [private] |
Definition at line 251 of file inmemory_database.h.
Referenced by close(), get_metadata(), open_metadata_keylist(), and set_metadata().
bool InMemoryDatabase::positions_present [private] |
Definition at line 257 of file inmemory_database.h.
Referenced by delete_document(), finish_add_doc(), and has_positions().
map<string, InMemoryTerm> InMemoryDatabase::postlists [private] |
Definition at line 243 of file inmemory_database.h.
Referenced by close(), delete_document(), finish_add_doc(), get_collection_freq(), get_termfreq(), InMemoryDatabase(), make_posting(), make_term(), open_allterms(), open_post_list(), replace_document(), and term_exists().
vector<InMemoryDoc> InMemoryDatabase::termlists [private] |
Definition at line 244 of file inmemory_database.h.
Referenced by close(), delete_document(), doc_exists(), finish_add_doc(), get_lastdocid(), make_doc(), make_posting(), open_position_list(), open_term_list(), positionlist_count(), and replace_document().
Xapian::doccount InMemoryDatabase::totdocs [private] |
Definition at line 253 of file inmemory_database.h.
Referenced by delete_document(), finish_add_doc(), get_avlength(), get_doccount(), and replace_document().
totlen_t InMemoryDatabase::totlen [private] |
Definition at line 255 of file inmemory_database.h.
Referenced by delete_document(), finish_add_doc(), get_avlength(), get_total_length(), and replace_document().
vector<std::map<Xapian::valueno, string> > InMemoryDatabase::valuelists [private] |
Definition at line 246 of file inmemory_database.h.
Referenced by add_values(), close(), delete_document(), InMemoryDocument::do_get_value(), and replace_document().
std::map<Xapian::valueno, ValueStats> InMemoryDatabase::valuestats [private] |
Definition at line 247 of file inmemory_database.h.
Referenced by add_values(), close(), delete_document(), get_value_freq(), get_value_lower_bound(), get_value_upper_bound(), and replace_document().