InMemoryDatabase Class Reference

A database held entirely in memory. More...

#include <inmemory_database.h>

Inheritance diagram for InMemoryDatabase:

Inheritance graph
[legend]
Collaboration diagram for InMemoryDatabase:

Collaboration graph
[legend]

List of all members.

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.
LeafPostListopen_post_list (const string &tname) const
 Open a posting list.
TermListopen_term_list (Xapian::docid did) const
 Open a term list.
Xapian::Document::Internalopen_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.
TermListopen_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
PositionListopen_position_list (Xapian::docid did, const string &tname) const
 Open a position list for the given term in the given document.
TermListopen_allterms (const string &prefix) const
 Open an allterms list.
 XAPIAN_NORETURN (static void throw_database_closed())

Private Member Functions

InMemoryDatabaseoperator= (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, InMemoryTermpostlists
vector< InMemoryDoctermlists
vector< std::string > doclists
vector< std::map
< Xapian::valueno, string > > 
valuelists
std::map< Xapian::valueno,
ValueStats
valuestats
vector< Xapian::termcountdoclengths
std::map< string, string > metadata
Xapian::doccount totdocs
totlen_t totlen
bool positions_present
bool closed

Friends

class InMemoryAllDocsPostList
class InMemoryDocument


Detailed Description

A database held entirely in memory.

This is a prototype database, mainly used for debugging and testing.

Definition at line 239 of file inmemory_database.h.


Constructor & Destructor Documentation

InMemoryDatabase::InMemoryDatabase ( const InMemoryDatabase  )  [private]

InMemoryDatabase::InMemoryDatabase (  ) 

Create and open an in-memory database.

Exceptions:
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().


Member Function Documentation

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]

void InMemoryDatabase::finish_add_doc ( Xapian::docid  did,
const Xapian::Document document 
) [private]

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.

References closed, totdocs, and totlen.

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.

Parameters:
tname The term whose collection frequency is being requested.

Implements Xapian::Database::Internal.

Definition at line 455 of file inmemory_database.cc.

References closed, and postlists.

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.

References closed, and totdocs.

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.

Parameters:
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.

References closed, and termlists.

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.

References closed, and metadata.

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.

Parameters:
tname The term whose term frequency is being requested.

Implements Xapian::Database::Internal.

Definition at line 446 of file inmemory_database.cc.

References closed, and postlists.

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.

Parameters:
slot The value slot to examine.
Exceptions:
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.

Parameters:
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.

Parameters:
slot The value slot to examine.
Exceptions:
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]

Definition at line 313 of file inmemory_database.h.

References closed.

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]

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

Parameters:
prefix The prefix to restrict the terms to.
Returns:
A pointer to the newly created allterms list. This object must be deleted by the caller after use.

Implements Xapian::Database::Internal.

Definition at line 904 of file inmemory_database.cc.

References closed, and postlists.

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.

Parameters:
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).
Returns:
A pointer to the newly created document object. This object must be deleted by the caller after use.

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.

Parameters:
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.

Parameters:
did The document id for which a position list is being requested.
tname The term for which a position list is being requested.
Returns:
A pointer to the newly created position list. This object must be deleted by the caller after use.

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.

Parameters:
tname The term whose posting list is being requested.
Returns:
A pointer to the newly created posting list. If the term doesn't exist, a LeafPostList object returning no documents is returned, which makes it easier to implement a search over multiple databases. This object must be deleted by the caller after use.

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.

Parameters:
did The document id whose term list is being requested.
Returns:
A pointer to the newly created term list. This object must be deleted by the caller after use.

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.

References closed, and metadata.

bool InMemoryDatabase::term_exists ( const string &  tname  )  const [virtual]

Check whether a given term is in the database.

Parameters:
tname The term whose presence is being checked.

Implements Xapian::Database::Internal.

Definition at line 887 of file inmemory_database.cc.

References Assert, closed, and postlists.

InMemoryDatabase::XAPIAN_NORETURN ( static void   throw_database_closed()  ) 


Friends And Related Function Documentation

friend class InMemoryAllDocsPostList [friend]

Definition at line 240 of file inmemory_database.h.

Referenced by open_post_list().

friend class InMemoryDocument [friend]

Definition at line 241 of file inmemory_database.h.

Referenced by open_document().


Member Data Documentation

bool InMemoryDatabase::closed [private]

vector<std::string> InMemoryDatabase::doclists [private]

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().

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]

vector<std::map<Xapian::valueno, string> > InMemoryDatabase::valuelists [private]


The documentation for this class was generated from the following files:

Documentation for Xapian (version 1.2.8).
Generated on 14 Dec 2011 by Doxygen 1.5.9.