QuartzWritableDatabase Class Reference

A writable quartz database. More...

#include <quartz_database.h>

Inheritance diagram for QuartzWritableDatabase:

Inheritance graph
[legend]
Collaboration diagram for QuartzWritableDatabase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 QuartzWritableDatabase (const string &dir, int action, int block_size)
 Create and open a writable quartz database.
 ~QuartzWritableDatabase ()
Xapian::doccount get_doccount () const
 Virtual methods of Database.
Xapian::docid get_lastdocid () const
 Return the last used document id of this (sub) database.
Xapian::doclength get_avlength () const
 Return the average length of a document in this (sub) database.
Xapian::doclength 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.
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=false) const
 Open a document.
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.

Private Member Functions

void flush ()
 Implementation of virtual methods: see Database for details.
void do_flush_const () const
void cancel ()
 Cancel pending modifications to the database.
virtual Xapian::docid add_document (const Xapian::Document &document)
 Add a new document to the database.
Xapian::docid add_document_ (Xapian::docid did, const Xapian::Document &document)
virtual void delete_document (Xapian::docid did)
 Delete a document in the database.
virtual void replace_document (Xapian::docid did, const Xapian::Document &document)
 Replace a given document in the database.

Private Attributes

map< string, pair< Xapian::termcount_diff,
Xapian::termcount_diff > > 
freq_deltas
 Unflushed changes to term frequencies and collection frequencies.
map< Xapian::docid, Xapian::termcountdoclens
 Document lengths of new and modified documents which haven't been flushed yet.
map< string, map< Xapian::docid,
pair< char, Xapian::termcount > > > 
mod_plists
 Modifications to posting lists.
QuartzDatabase database_ro
 The readonly database encapsulated in the writable database.
quartz_totlen_t total_length
 Total length of all documents including unflushed modifications.
Xapian::docid lastdocid
 Highest document ID ever allocated by this database.
Xapian::doccount changes_made
 The number of documents added, deleted, or replaced since the last flush.

Static Private Attributes

static size_t flush_threshold = 0

Detailed Description

A writable quartz database.

Definition at line 229 of file quartz_database.h.


Constructor & Destructor Documentation

QuartzWritableDatabase::QuartzWritableDatabase ( const string &  dir,
int  action,
int  block_size 
)

Create and open a writable quartz database.

Exceptions:
Xapian::DatabaseOpeningError thrown if database can't be opened.
Xapian::DatabaseVersionError thrown if database is in an unsupported format. This implies that the database was created by an older or newer version of Xapian.
Parameters:
dir directory holding quartz tables

Definition at line 669 of file quartz_database.cc.

References atoi(), DEBUGCALL, and flush_threshold.

QuartzWritableDatabase::~QuartzWritableDatabase (  ) 

Definition at line 688 of file quartz_database.cc.

References DEBUGCALL, and Xapian::Database::Internal::dtor_called().


Member Function Documentation

void QuartzWritableDatabase::flush (  )  [private, virtual]

Implementation of virtual methods: see Database for details.

Reimplemented from Xapian::Database::Internal.

Definition at line 695 of file quartz_database.cc.

References changes_made, do_flush_const(), and Xapian::Database::Internal::transaction_active().

void QuartzWritableDatabase::do_flush_const (  )  const [private]

Definition at line 703 of file quartz_database.cc.

References QuartzDatabase::apply(), changes_made, database_ro, DEBUGCALL, doclens, freq_deltas, lastdocid, QuartzPostListTable::merge_changes(), mod_plists, QuartzDatabase::postlist_table, QuartzDatabase::record_table, QuartzRecordTable::set_total_length_and_lastdocid(), and total_length.

Referenced by add_document_(), delete_document(), flush(), open_allterms(), open_post_list(), and replace_document().

void QuartzWritableDatabase::cancel (  )  [private, virtual]

Cancel pending modifications to the database.

Reimplemented from Xapian::Database::Internal.

Definition at line 1201 of file quartz_database.cc.

References QuartzDatabase::cancel(), changes_made, database_ro, doclens, freq_deltas, QuartzDatabase::get_lastdocid(), QuartzRecordTable::get_total_length(), lastdocid, mod_plists, QuartzDatabase::record_table, and total_length.

Referenced by add_document_(), delete_document(), and replace_document().

Xapian::docid QuartzWritableDatabase::add_document ( const Xapian::Document document  )  [private, virtual]

Add a new document to the database.

See WritableDatabase::add_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 720 of file quartz_database.cc.

References add_document_(), DEBUGCALL, lastdocid, and RETURN.

Xapian::docid QuartzWritableDatabase::add_document_ ( Xapian::docid  did,
const Xapian::Document document 
) [private]

Definition at line 732 of file quartz_database.cc.

References Assert, cancel(), changes_made, database_ro, do_flush_const(), doclens, QuartzValueTable::encode_values(), flush_threshold, freq_deltas, Xapian::Document::get_data(), Xapian::TermIterator::get_wdf(), mod_plists, Xapian::TermIterator::positionlist_begin(), Xapian::TermIterator::positionlist_end(), QuartzDatabase::positionlist_table, QuartzDatabase::record_table, QuartzRecordTable::replace_record(), QuartzValueTable::set_encoded_values(), QuartzTermListTable::set_entries(), QuartzPositionListTable::set_positionlist(), Xapian::Document::termlist_begin(), Xapian::Document::termlist_end(), QuartzDatabase::termlist_table, total_length, Xapian::Database::Internal::transaction_active(), QuartzDatabase::value_table, Xapian::Document::values_begin(), and Xapian::Document::values_end().

Referenced by add_document(), and replace_document().

void QuartzWritableDatabase::delete_document ( Xapian::docid  did  )  [private, virtual]

Delete a document in the database.

See WritableDatabase::delete_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 821 of file quartz_database.cc.

References Assert, QuartzTermList::at_end(), cancel(), changes_made, database_ro, DEBUGCALL, QuartzValueTable::delete_all_values(), QuartzPositionListTable::delete_positionlist(), QuartzRecordTable::delete_record(), QuartzTermListTable::delete_termlist(), do_flush_const(), doclens, flush_threshold, freq_deltas, get_doccount(), QuartzTermList::get_doclength(), QuartzTermList::get_termname(), QuartzTermList::get_wdf(), mod_plists, QuartzTermList::next(), QuartzDatabase::positionlist_table, QuartzDatabase::record_table, QuartzDatabase::termlist_table, total_length, Xapian::Database::Internal::transaction_active(), and QuartzDatabase::value_table.

void QuartzWritableDatabase::replace_document ( Xapian::docid  did,
const Xapian::Document document 
) [private, virtual]

Replace a given document in the database.

See WritableDatabase::replace_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 897 of file quartz_database.cc.

References add_document_(), Assert, QuartzTermList::at_end(), cancel(), changes_made, database_ro, DEBUGCALL, QuartzValueTable::delete_all_values(), QuartzPositionListTable::delete_positionlist(), do_flush_const(), doclens, QuartzValueTable::encode_values(), flush_threshold, freq_deltas, Xapian::Document::get_data(), get_doccount(), QuartzTermList::get_doclength(), QuartzTermList::get_termname(), Xapian::TermIterator::get_wdf(), QuartzTermList::get_wdf(), lastdocid, mod_plists, QuartzTermList::next(), Xapian::TermIterator::positionlist_begin(), Xapian::TermIterator::positionlist_end(), QuartzDatabase::positionlist_table, QuartzDatabase::record_table, QuartzRecordTable::replace_record(), QuartzValueTable::set_encoded_values(), QuartzTermListTable::set_entries(), QuartzPositionListTable::set_positionlist(), Xapian::Document::termlist_begin(), Xapian::Document::termlist_end(), QuartzDatabase::termlist_table, total_length, Xapian::Database::Internal::transaction_active(), QuartzDatabase::value_table, Xapian::Document::values_begin(), and Xapian::Document::values_end().

Xapian::doccount QuartzWritableDatabase::get_doccount (  )  const [virtual]

Virtual methods of Database.

Implements Xapian::Database::Internal.

Definition at line 1043 of file quartz_database.cc.

References database_ro, DEBUGCALL, QuartzDatabase::get_doccount(), and RETURN.

Referenced by delete_document(), open_post_list(), open_term_list(), and replace_document().

Xapian::docid QuartzWritableDatabase::get_lastdocid (  )  const [virtual]

Return the last used document id of this (sub) database.

Implements Xapian::Database::Internal.

Definition at line 1050 of file quartz_database.cc.

References DEBUGCALL, lastdocid, and RETURN.

Xapian::doclength QuartzWritableDatabase::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 1057 of file quartz_database.cc.

References database_ro, DEBUGCALL, QuartzDatabase::get_doccount(), RETURN, and total_length.

Xapian::doclength QuartzWritableDatabase::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 1066 of file quartz_database.cc.

References database_ro, DEBUGCALL, doclens, QuartzDatabase::get_doclength(), and RETURN.

Xapian::doccount QuartzWritableDatabase::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 1076 of file quartz_database.cc.

References database_ro, DEBUGCALL, freq_deltas, QuartzDatabase::get_termfreq(), and RETURN.

Referenced by term_exists().

Xapian::termcount QuartzWritableDatabase::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 ocurrences 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 1087 of file quartz_database.cc.

References database_ro, DEBUGCALL, freq_deltas, QuartzDatabase::get_collection_freq(), and RETURN.

bool QuartzWritableDatabase::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 1100 of file quartz_database.cc.

References DEBUGCALL, get_termfreq(), and RETURN.

bool QuartzWritableDatabase::has_positions (  )  const [virtual]

Check whether this database contains any positional information.

Implements Xapian::Database::Internal.

Definition at line 1107 of file quartz_database.cc.

References database_ro, and QuartzDatabase::has_positions().

LeafPostList * QuartzWritableDatabase::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 new EmptyPostList object (or an object which behaves the same way) is returned instead, 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 1114 of file quartz_database.cc.

References database_ro, DEBUGCALL, do_flush_const(), get_doccount(), mod_plists, QuartzDatabase::positionlist_table, QuartzDatabase::postlist_table, RETURN, QuartzDatabase::termlist_table, and Xapian::Database::Internal::transaction_active().

TermList * QuartzWritableDatabase::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 1141 of file quartz_database.cc.

References Assert, database_ro, DEBUGCALL, get_doccount(), RETURN, and QuartzDatabase::termlist_table.

Referenced by open_position_list().

Xapian::Document::Internal * QuartzWritableDatabase::open_document ( Xapian::docid  did,
bool  lazy = false 
) 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 Don't check the document exists immediately - use from within the matcher where we know the document exists, and don't want to read the record when we just want the values.
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 1153 of file quartz_database.cc.

References Assert, database_ro, DEBUGCALL, QuartzDatabase::record_table, RETURN, and QuartzDatabase::value_table.

PositionList * QuartzWritableDatabase::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 1167 of file quartz_database.cc.

References Assert, database_ro, open_term_list(), QuartzDatabase::positionlist_table, and AutoPtr< _Tp >::release().

TermList * QuartzWritableDatabase::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 1187 of file quartz_database.cc.

References changes_made, Btree::cursor_get(), database_ro, DEBUGCALL, do_flush_const(), Btree::get_entry_count(), QuartzDatabase::postlist_table, RETURN, and Xapian::Database::Internal::transaction_active().


Member Data Documentation

map<string, pair<Xapian::termcount_diff, Xapian::termcount_diff> > QuartzWritableDatabase::freq_deltas [mutable, private]

Unflushed changes to term frequencies and collection frequencies.

Definition at line 233 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), get_collection_freq(), get_termfreq(), and replace_document().

map<Xapian::docid, Xapian::termcount> QuartzWritableDatabase::doclens [mutable, private]

Document lengths of new and modified documents which haven't been flushed yet.

Definition at line 236 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), get_doclength(), and replace_document().

map<string, map<Xapian::docid, pair<char, Xapian::termcount> > > QuartzWritableDatabase::mod_plists [mutable, private]

Modifications to posting lists.

Definition at line 240 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), open_post_list(), and replace_document().

QuartzDatabase QuartzWritableDatabase::database_ro [mutable, private]

The readonly database encapsulated in the writable database.

Definition at line 244 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), get_avlength(), get_collection_freq(), get_doccount(), get_doclength(), get_termfreq(), has_positions(), open_allterms(), open_document(), open_position_list(), open_post_list(), open_term_list(), and replace_document().

quartz_totlen_t QuartzWritableDatabase::total_length [mutable, private]

Total length of all documents including unflushed modifications.

Definition at line 248 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), get_avlength(), and replace_document().

Xapian::docid QuartzWritableDatabase::lastdocid [mutable, private]

Highest document ID ever allocated by this database.

Definition at line 252 of file quartz_database.h.

Referenced by add_document(), cancel(), do_flush_const(), get_lastdocid(), and replace_document().

Xapian::doccount QuartzWritableDatabase::changes_made [mutable, private]

The number of documents added, deleted, or replaced since the last flush.

Definition at line 257 of file quartz_database.h.

Referenced by add_document_(), cancel(), delete_document(), do_flush_const(), flush(), open_allterms(), and replace_document().

size_t QuartzWritableDatabase::flush_threshold = 0 [static, private]

Definition at line 259 of file quartz_database.h.

Referenced by add_document_(), delete_document(), QuartzWritableDatabase(), and replace_document().


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.