Xapian::Database Class Reference

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

#include <database.h>

Inheritance diagram for Xapian::Database:

Inheritance graph
[legend]
List of all members.

Public Member Functions

void add_database (const Database &database)
 Add an existing database (or group of databases) to those accessed by this object.
 Database ()
 Create a Database with no databases in.
 Database (const std::string &path)
 Open a Database, automatically determining the database backend to use.
virtual ~Database ()
 Destroy this handle on the database.
 Database (const Database &other)
 Copying is allowed.
void operator= (const Database &other)
 Assignment is allowed.
void reopen ()
 Re-open the database.
virtual std::string get_description () const
 Return a string describing this object.
PostingIterator postlist_begin (const std::string &tname) const
 An iterator pointing to the start of the postlist for a given term.
PostingIterator postlist_end (const std::string &) const
 Corresponding end iterator to postlist_begin().
TermIterator termlist_begin (Xapian::docid did) const
 An iterator pointing to the start of the termlist for a given document.
TermIterator termlist_end (Xapian::docid) const
 Corresponding end iterator to termlist_begin().
bool has_positions () const
 Does this database have any positional information?
PositionIterator 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 positionlist_end (Xapian::docid, const std::string &) const
 Corresponding end iterator to positionlist_begin().
TermIterator allterms_begin () const
 An iterator which runs across all terms in the database.
TermIterator allterms_end () const
 Corresponding end iterator to allterms_begin().
TermIterator allterms_begin (const std::string &prefix) const
 An iterator which runs across all terms with a given prefix.
TermIterator allterms_end (const std::string &) const
 Corresponding end iterator to allterms_begin(prefix).
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
 Check if a given term exists in the database.
Xapian::termcount get_collection_freq (const std::string &tname) const
 Return the total number of occurrences of the given term.
Xapian::doclength get_doclength (Xapian::docid did) const
 Get the length of a document.
void keep_alive ()
 Send a "keep-alive" to remote databases to stop them timing out.
Xapian::Document get_document (Xapian::docid did) const
 Get a document from the database, given its document id.
std::string get_spelling_suggestion (const std::string &word, unsigned max_edit_distance=2) const
 Suggest a spelling correction.
Xapian::TermIterator spellings_begin () const
 An iterator which returns all the spelling correction targets.
Xapian::TermIterator spellings_end () const
 Corresponding end iterator to spellings_begin().
Xapian::TermIterator synonyms_begin (const std::string &term) const
 An iterator which returns all the synonyms for a given term.
Xapian::TermIterator synonyms_end (const std::string &) const
 Corresponding end iterator to synonyms_begin(term).
Xapian::TermIterator synonym_keys_begin (const std::string &prefix="") const
 An iterator which returns all terms which have synonyms.
Xapian::TermIterator synonym_keys_end (const std::string &="") const
 Corresponding end iterator to synonym_keys_begin(prefix).
std::string get_metadata (const std::string &key) const
 Get the user-specified metadata associated with a given key.
Xapian::TermIterator metadata_keys_begin (const std::string &prefix="") const
 An iterator which returns all user-specified metadata keys.
Xapian::TermIterator metadata_keys_end (const std::string &="") const
 Corresponding end iterator to metadata_keys_begin().

Private Member Functions

 Database (Internal *internal)
 

For internal use only.

Create a Database from its internals.



Private Attributes

std::vector< Xapian::Internal::RefCntPtr<
Internal > > 
internal
 

For internal use only.

Reference counted internals.



Classes

class  Internal
 Base class for databases. More...

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

Definition at line 57 of file database.h.


Constructor & Destructor Documentation

Xapian::Database::Database (  ) 

Create a Database with no databases in.

Definition at line 54 of file omdatabase.cc.

References DEBUGAPICALL.

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.

Xapian::Database::Database ( Internal internal  )  [explicit, private]

For internal use only.

Create a Database from its internals.

Definition at line 59 of file omdatabase.cc.

References DEBUGAPICALL.

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.

Definition at line 84 of file omdatabase.cc.

References DEBUGAPICALL.

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

Copying is allowed.

The internals are reference counted, so copying is cheap.

Definition at line 66 of file omdatabase.cc.

References DEBUGAPICALL, and internal.


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.

Definition at line 100 of file omdatabase.cc.

References DEBUGAPICALL, DEBUGLINE, and internal.

Referenced by DEFINE_TESTCASE(), main(), Xapian::open_stub(), RemoteServer::RemoteServer(), and test_qp_spell2().

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

Assignment is allowed.

The internals are reference counted, so assignment is cheap.

Definition at line 73 of file omdatabase.cc.

References DEBUGAPICALL, DEBUGLINE, and internal.

Referenced by Xapian::WritableDatabase::operator=().

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.

Definition at line 90 of file omdatabase.cc.

References DEBUGAPICALL.

Referenced by DEFINE_TESTCASE().

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

Return a string describing this object.

Todo:
display contents of the database

Reimplemented in Xapian::WritableDatabase.

Definition at line 343 of file omdatabase.cc.

Referenced by Xapian::Enquire::Internal::get_description().

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.

Referenced by DEFINE_TESTCASE(), and main().

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

Corresponding end iterator to postlist_begin().

Definition at line 124 of file database.h.

Referenced by DEFINE_TESTCASE(), and main().

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

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

Definition at line 148 of file omdatabase.cc.

References Assert, DEBUGAPICALL, and RETURN.

Referenced by RSetI::calculate_stats(), DEFINE_TESTCASE(), Xapian::Enquire::Internal::get_matching_terms(), MultiMatch::get_mset(), show_termlists(), and test_termlist3_helper().

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

Corresponding end iterator to termlist_begin().

Definition at line 135 of file database.h.

Referenced by RSetI::calculate_stats(), DEFINE_TESTCASE(), Xapian::Enquire::Internal::get_matching_terms(), MultiMatch::get_mset(), and show_termlists().

bool Xapian::Database::has_positions (  )  const

Does this database have any positional information?

Definition at line 188 of file omdatabase.cc.

References DEBUGAPICALL, and RETURN.

Referenced by DEFINE_TESTCASE(), and RemoteServer::RemoteServer().

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.

Referenced by DEFINE_TESTCASE(), test_emptyterm1_helper(), and test_emptyterm2_helper().

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

Corresponding end iterator to positionlist_begin().

Definition at line 149 of file database.h.

Referenced by DEFINE_TESTCASE().

TermIterator Xapian::Database::allterms_begin (  )  const

An iterator which runs across all terms in the database.

Definition at line 170 of file omdatabase.cc.

Referenced by Term::as_partial_query(), Term::as_wildcarded_query(), DEFINE_TESTCASE(), and show_db_stats().

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

Corresponding end iterator to allterms_begin().

Definition at line 159 of file database.h.

Referenced by Term::as_partial_query(), Term::as_wildcarded_query(), DEFINE_TESTCASE(), and show_db_stats().

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.

Definition at line 176 of file omdatabase.cc.

References DEBUGAPICALL, RETURN, and size.

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

Corresponding end iterator to allterms_begin(prefix).

Definition at line 178 of file database.h.

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

Get the number of documents in the database.

Definition at line 217 of file omdatabase.cc.

References DEBUGAPICALL, and RETURN.

Referenced by DEFINE_TESTCASE(), Xapian::Internal::ExpandWeight::get_weight(), main(), MultiTermList::MultiTermList(), RemoteServer::RemoteServer(), show_db_stats(), test_emptyterm1_helper(), and test_emptyterm2_helper().

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

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

Definition at line 229 of file omdatabase.cc.

References Assert, DEBUGAPICALL, and RETURN.

Referenced by DEFINE_TESTCASE(), main(), and RemoteServer::RemoteServer().

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

Get the average length of the documents in the database.

Definition at line 244 of file omdatabase.cc.

References DEBUGAPICALL, DEBUGLINE, RETURN, and size.

Referenced by DEFINE_TESTCASE(), Xapian::Internal::ExpandWeight::get_weight(), RemoteServer::RemoteServer(), and show_db_stats().

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

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

Referenced by DEFINE_TESTCASE(), Xapian::Internal::ExpandWeight::get_weight(), test_emptyterm1_helper(), and test_emptyterm2_helper().

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.

Referenced by DEFINE_TESTCASE(), Xapian::QueryParser::Internal::parse_term(), test_emptyterm1_helper(), and test_emptyterm2_helper().

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.

Referenced by DEFINE_TESTCASE(), test_emptyterm1_helper(), and test_emptyterm2_helper().

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

Get the length of a document.

Definition at line 292 of file omdatabase.cc.

References Assert, DEBUGAPICALL, and RETURN.

Referenced by DEFINE_TESTCASE(), and MultiPostList::get_doclength().

void Xapian::Database::keep_alive (  ) 

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

Definition at line 333 of file omdatabase.cc.

References DEBUGAPICALL.

Referenced by DEFINE_TESTCASE().

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 for which to retrieve the data.
Returns:
A Xapian::Document object containing the document data
Exceptions:
Xapian::DocNotFoundError The document specified could not be found in the database.

Definition at line 305 of file omdatabase.cc.

References Assert, DEBUGAPICALL, and RETURN.

Referenced by DEFINE_TESTCASE(), main(), show_docdata(), and show_values().

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

Referenced by DEFINE_TESTCASE(), and test_tg_spell1().

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 488 of file omdatabase.cc.

References DEBUGAPICALL, AutoPtr< _Tp >::get(), AutoPtr< _Tp >::release(), and RETURN.

Referenced by DEFINE_TESTCASE(), and main().

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

Corresponding end iterator to spellings_begin().

Definition at line 257 of file database.h.

Referenced by DEFINE_TESTCASE(), and main().

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.

Definition at line 506 of file omdatabase.cc.

References DEBUGAPICALL, AutoPtr< _Tp >::get(), AutoPtr< _Tp >::release(), and RETURN.

Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), Term::get_query_with_synonyms(), and main().

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

Corresponding end iterator to synonyms_begin(term).

Definition at line 268 of file database.h.

Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), Term::get_query_with_synonyms(), and main().

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

An iterator which returns all terms which have synonyms.

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

Definition at line 524 of file omdatabase.cc.

References DEBUGAPICALL, AutoPtr< _Tp >::get(), AutoPtr< _Tp >::release(), and RETURN.

Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), and main().

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

Corresponding end iterator to synonym_keys_begin(prefix).

Definition at line 280 of file database.h.

Referenced by TermGroup::as_group(), DEFINE_TESTCASE(), and main().

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::UnimplementedError will be thrown if the database backend in use doesn't support user-specified metadata.

Referenced by DEFINE_TESTCASE(), and main().

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

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

Definition at line 551 of file omdatabase.cc.

References DEBUGAPICALL, and RETURN.

Referenced by main().

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

Corresponding end iterator to metadata_keys_begin().

Definition at line 326 of file database.h.

Referenced by main().


Member Data Documentation

std::vector<Xapian::Internal::RefCntPtr<Internal> > Xapian::Database::internal [private]

For internal use only.

Reference counted internals.

Definition at line 59 of file database.h.

Referenced by add_database(), OmExpand::build_tree(), Database(), MultiMatch::get_collapse_key(), MultiMatch::get_mset(), Xapian::Enquire::Internal::Internal(), MultiMatch::MultiMatch(), MultiTermList::MultiTermList(), operator=(), Xapian::Enquire::Internal::read_doc(), and Xapian::Enquire::Internal::request_doc().


The documentation for this class was generated from the following files:
Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.