Xapian::Database Class Reference

#include <database.h>

Inheritance diagram for Xapian::Database:

Inheritance graph
[legend]
List of all members.

Public Member Functions

void add_database (const Database &database)
 Database ()
 Database (const std::string &path)
virtual ~Database ()
 Database (const Database &other)
void operator= (const Database &other)
void reopen ()
virtual void close ()
virtual std::string get_description () const
 Return a string describing this object.
PostingIterator postlist_begin (const std::string &tname) const
PostingIterator postlist_end (const std::string &) const
TermIterator termlist_begin (Xapian::docid did) const
TermIterator termlist_end (Xapian::docid) const
bool has_positions () const
PositionIterator positionlist_begin (Xapian::docid did, const std::string &tname) const
PositionIterator positionlist_end (Xapian::docid, const std::string &) const
TermIterator allterms_begin () const
TermIterator allterms_end () const
TermIterator allterms_begin (const std::string &prefix) const
TermIterator allterms_end (const std::string &) const
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::doclength get_avlength () const
 Get the average length of the documents in the database.
Xapian::doccount get_termfreq (const std::string &tname) const
 Get the number of documents in the database indexed by a given term.
bool term_exists (const std::string &tname) const
Xapian::termcount get_collection_freq (const std::string &tname) const
Xapian::doccount get_value_freq (Xapian::valueno valno) const
std::string get_value_lower_bound (Xapian::valueno valno) const
std::string get_value_upper_bound (Xapian::valueno valno) const
Xapian::termcount get_doclength_lower_bound () const
Xapian::termcount get_doclength_upper_bound () const
 Get an upper bound on the length of a document in this DB.
Xapian::termcount get_wdf_upper_bound (const std::string &term) const
 Get an upper bound on the wdf of term term.
ValueIterator valuestream_begin (Xapian::valueno slot) const
 Return an iterator over the value in slot slot for each document.
ValueIteratorEnd_ valuestream_end (Xapian::valueno) const
 Return end iterator corresponding to valuestream_begin().
Xapian::termcount get_doclength (Xapian::docid did) const
 Get the length of a document.
void keep_alive ()
Xapian::Document get_document (Xapian::docid did) const
std::string get_spelling_suggestion (const std::string &word, unsigned max_edit_distance=2) const
Xapian::TermIterator spellings_begin () const
Xapian::TermIterator spellings_end () const
 Corresponding end iterator to spellings_begin().
Xapian::TermIterator synonyms_begin (const std::string &term) const
Xapian::TermIterator synonyms_end (const std::string &) const
 Corresponding end iterator to synonyms_begin(term).
Xapian::TermIterator synonym_keys_begin (const std::string &prefix=std::string()) const
Xapian::TermIterator synonym_keys_end (const std::string &=std::string()) const
 Corresponding end iterator to synonym_keys_begin(prefix).
std::string get_metadata (const std::string &key) const
Xapian::TermIterator metadata_keys_begin (const std::string &prefix=std::string()) const
Xapian::TermIterator metadata_keys_end (const std::string &=std::string()) const
 Corresponding end iterator to metadata_keys_begin().
std::string get_uuid () const

Detailed Description

This class is used to access a database, or a group of databases.

For searching, this class is used in conjunction with an Enquire object.

Exceptions:
InvalidArgumentError will be thrown if an invalid argument is supplied, for example, an unknown database type.
DatabaseOpeningError may be thrown if the database cannot be opened (for example, a required file cannot be found).
DatabaseVersionError may be thrown if the database is in an unsupported format (for example, created by a newer version of Xapian which uses an incompatible format).


Constructor & Destructor Documentation

Xapian::Database::Database (  ) 

Create a Database with no databases in.

Xapian::Database::Database ( const std::string &  path  )  [explicit]

Open a Database, automatically determining the database backend to use.

Parameters:
path directory that the database is stored in.

virtual Xapian::Database::~Database (  )  [virtual]

Destroy this handle on the database.

If there are no copies of this object remaining, the database(s) will be closed.

Xapian::Database::Database ( const Database other  ) 

Copying is allowed. The internals are reference counted, so copying is cheap.


Member Function Documentation

void Xapian::Database::add_database ( const Database database  ) 

Add an existing database (or group of databases) to those accessed by this object.

Parameters:
database the database(s) to add.

void Xapian::Database::operator= ( const Database other  ) 

Assignment is allowed. The internals are reference counted, so assignment is cheap.

void Xapian::Database::reopen (  ) 

Re-open the database.

This re-opens the database(s) to the latest available version(s). It can be used either to make sure the latest results are returned, or to recover from a Xapian::DatabaseModifiedError.

Calling reopen() on a database which has been closed (with close()) will always raise a Xapian::DatabaseError.

virtual void Xapian::Database::close (  )  [virtual]

Close the database.

This closes the database and releases all file handles held by the database.

This is a permanent close of the database: calling reopen() after closing a database will not reopen it, and will raise an exception.

Calling close() on a database which is already closed has no effect (and doesn't raise an exception).

After this call, calls made to methods of the database (other than close() or the destructor), or to objects associated with the database will behave in one of the following ways (but which behaviour happens may vary between releases, and between database backends):

To summarise - you should not rely on the exception being raised, or the normal result being available, but if you do get a result, it will be correct.

virtual std::string Xapian::Database::get_description (  )  const [virtual]

Return a string describing this object.

Reimplemented in Xapian::WritableDatabase.

PostingIterator Xapian::Database::postlist_begin ( const std::string &  tname  )  const

An iterator pointing to the start of the postlist for a given term.

If the term name is the empty string, the iterator returned will list all the documents in the database. Such an iterator will always return a WDF value of 1, since there is no obvious meaning for this quantity in this case.

PostingIterator Xapian::Database::postlist_end ( const std::string &   )  const [inline]

Corresponding end iterator to postlist_begin().

TermIterator Xapian::Database::termlist_begin ( Xapian::docid  did  )  const

An iterator pointing to the start of the termlist for a given document.

TermIterator Xapian::Database::termlist_end ( Xapian::docid   )  const [inline]

Corresponding end iterator to termlist_begin().

bool Xapian::Database::has_positions (  )  const

Does this database have any positional information?

PositionIterator Xapian::Database::positionlist_begin ( Xapian::docid  did,
const std::string &  tname 
) const

An iterator pointing to the start of the position list for a given term in a given document.

PositionIterator Xapian::Database::positionlist_end ( Xapian::docid  ,
const std::string &   
) const [inline]

Corresponding end iterator to positionlist_begin().

TermIterator Xapian::Database::allterms_begin (  )  const

An iterator which runs across all terms in the database.

TermIterator Xapian::Database::allterms_end (  )  const [inline]

Corresponding end iterator to allterms_begin().

TermIterator Xapian::Database::allterms_begin ( const std::string &  prefix  )  const

An iterator which runs across all terms with a given prefix.

This is functionally similar to getting an iterator with allterms_begin() and then calling skip_to(prefix) on that iterator to move to the start of the prefix, but is more convenient (because it detects the end of the prefixed terms), and may be more efficient than simply calling skip_to() after opening the iterator, particularly for network databases.

Parameters:
prefix The prefix to restrict the returned terms to.

TermIterator Xapian::Database::allterms_end ( const std::string &   )  const [inline]

Corresponding end iterator to allterms_begin(prefix).

Xapian::doccount Xapian::Database::get_doccount (  )  const

Get the number of documents in the database.

Xapian::docid Xapian::Database::get_lastdocid (  )  const

Get the highest document id which has been used in the database.

Xapian::doclength Xapian::Database::get_avlength (  )  const

Get the average length of the documents in the database.

Xapian::doccount Xapian::Database::get_termfreq ( const std::string &  tname  )  const

Get the number of documents in the database indexed by a given term.

bool Xapian::Database::term_exists ( const std::string &  tname  )  const

Check if a given term exists in the database.

Return true if and only if the term exists in the database. This is the same as (get_termfreq(tname) != 0), but will often be more efficient.

Xapian::termcount Xapian::Database::get_collection_freq ( const std::string &  tname  )  const

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 it indexes: i.e., the sum of the within document frequencies of the term.

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

Xapian::doccount Xapian::Database::get_value_freq ( Xapian::valueno  valno  )  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.

Parameters:
valno The value slot to examine.
Exceptions:
UnimplementedError The frequency of the value isn't available for this database type.

std::string Xapian::Database::get_value_lower_bound ( Xapian::valueno  valno  )  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.

If the lower bound isn't available for the given database type, this will return the lowest possible bound - the empty string.

Parameters:
valno The value slot to examine.

std::string Xapian::Database::get_value_upper_bound ( Xapian::valueno  valno  )  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.

Parameters:
valno The value slot to examine.
Exceptions:
UnimplementedError The upper bound of the values isn't available for this database type.

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.

Xapian::termcount Xapian::Database::get_doclength_upper_bound (  )  const

Get an upper bound on the length of a document in this DB.

Xapian::termcount Xapian::Database::get_wdf_upper_bound ( const std::string &  term  )  const

Get an upper bound on the wdf of term term.

ValueIterator Xapian::Database::valuestream_begin ( Xapian::valueno  slot  )  const

Return an iterator over the value in slot slot for each document.

ValueIteratorEnd_ Xapian::Database::valuestream_end ( Xapian::valueno   )  const [inline]

Return end iterator corresponding to valuestream_begin().

Xapian::termcount Xapian::Database::get_doclength ( Xapian::docid  did  )  const

Get the length of a document.

void Xapian::Database::keep_alive (  ) 

Send a "keep-alive" to remote databases to stop them timing out.

Has no effect on non-remote databases.

Xapian::Document Xapian::Database::get_document ( Xapian::docid  did  )  const

Get a document from the database, given its document id.

This method returns a Xapian::Document object which provides the information about a document.

Parameters:
did The document id of the document to retrieve.
Returns:
A Xapian::Document object containing the document data
Exceptions:
Xapian::DocNotFoundError The document specified could not be found in the database.

std::string Xapian::Database::get_spelling_suggestion ( const std::string &  word,
unsigned  max_edit_distance = 2 
) const

Suggest a spelling correction.

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

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

Xapian::TermIterator Xapian::Database::spellings_end (  )  const [inline]

Corresponding end iterator to spellings_begin().

Xapian::TermIterator Xapian::Database::synonyms_begin ( const std::string &  term  )  const

An iterator which returns all the synonyms for a given term.

Parameters:
term The term to return synonyms for.

Xapian::TermIterator Xapian::Database::synonyms_end ( const std::string &   )  const [inline]

Corresponding end iterator to synonyms_begin(term).

Xapian::TermIterator Xapian::Database::synonym_keys_begin ( const std::string &  prefix = std::string()  )  const

An iterator which returns all terms which have synonyms.

Parameters:
prefix If non-empty, only terms with this prefix are returned.

Xapian::TermIterator Xapian::Database::synonym_keys_end ( const std::string &  = std::string()  )  const [inline]

Corresponding end iterator to synonym_keys_begin(prefix).

std::string Xapian::Database::get_metadata ( const std::string &  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,tag) 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.

Parameters:
key The key of the metadata item to access.
Returns:
The retrieved metadata item's value.
Exceptions:
Xapian::InvalidArgumentError will be thrown if the key supplied is empty.

Xapian::TermIterator Xapian::Database::metadata_keys_begin ( const std::string &  prefix = std::string()  )  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().

Parameters:
prefix If non-empty, only keys with this prefix are returned.
Exceptions:
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).

Xapian::TermIterator Xapian::Database::metadata_keys_end ( const std::string &  = std::string()  )  const [inline]

Corresponding end iterator to metadata_keys_begin().

std::string Xapian::Database::get_uuid (  )  const

Get a 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.


The documentation for this class was generated from the following file:
Documentation for Xapian (version 1.1.1).
Generated on 10 Jun 2009 by Doxygen 1.5.2.