FlintWritableDatabase Class Reference

A writable flint database. More...

#include <flint_database.h>

Inheritance diagram for FlintWritableDatabase:

Inheritance graph
[legend]
Collaboration diagram for FlintWritableDatabase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FlintWritableDatabase (const string &dir, int action, int block_size)
 Create and open a writable flint database.
 ~FlintWritableDatabase ()
Xapian::doclength get_doclength (Xapian::docid did) const
 Virtual methods of Database::Internal.
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.
LeafPostListopen_post_list (const string &tname) const
 Open a posting list.
TermListopen_allterms (const string &prefix) const
 Open an allterms list.
void add_spelling (const string &word, Xapian::termcount freqinc) const
 Add a word to the spelling dictionary.
void remove_spelling (const string &word, Xapian::termcount freqdec) const
 Remove a word from the spelling dictionary.
TermListopen_spelling_wordlist () const
 Return a termlist which returns the words which are spelling correction targets.
TermListopen_synonym_keylist (const string &prefix) const
 Open a termlist returning each term which has synonyms.
void add_synonym (const string &word, const string &synonym) const
 Add a synonym for a term.
void remove_synonym (const string &word, const string &synonym) const
 Remove a synonym for a term.
void clear_synonyms (const string &word) const
 Clear all synonyms for a term.
void set_metadata (const string &key, const string &value)
 Set the metadata associated with a given key.

Private Member Functions

void flush_postlist_changes () const
 Flush any unflushed postlist changes, but don't commit them.
void flush ()
 Implementation of virtual methods: see Database::Internal for details.
void cancel ()
 Cancel pending modifications to the database.
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)
void delete_document (Xapian::docid did)
 Delete a document in the database.
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.
Xapian::doccount change_count
 The number of documents added, deleted, or replaced since the last flush.
Xapian::doccount flush_threshold
 If change_count reaches this threshold we automatically flush.

Detailed Description

A writable flint database.

Definition at line 260 of file flint_database.h.


Constructor & Destructor Documentation

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

Create and open a writable flint 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 flint tables

Definition at line 658 of file flint_database.cc.

References atoi(), DEBUGCALL, and flush_threshold.

FlintWritableDatabase::~FlintWritableDatabase (  ) 

Definition at line 677 of file flint_database.cc.

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


Member Function Documentation

void FlintWritableDatabase::flush_postlist_changes (  )  const [private]

Flush any unflushed postlist changes, but don't commit them.

Definition at line 693 of file flint_database.cc.

References FlintTable::add(), change_count, doclens, freq_deltas, FlintDatabase::lastdocid, FlintPostListTable::merge_changes(), METAINFO_KEY(), mod_plists, pack_uint(), pack_uint_last(), FlintDatabase::postlist_table, and FlintDatabase::total_length.

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

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

Implementation of virtual methods: see Database::Internal for details.

Reimplemented from Xapian::Database::Internal.

Definition at line 684 of file flint_database.cc.

References FlintDatabase::apply(), change_count, flush_postlist_changes(), and Xapian::Database::Internal::transaction_active().

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

Cancel pending modifications to the database.

Reimplemented from FlintDatabase.

Definition at line 1114 of file flint_database.cc.

References FlintDatabase::cancel(), change_count, doclens, freq_deltas, mod_plists, and FlintDatabase::read_metainfo().

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

Xapian::docid FlintWritableDatabase::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 709 of file flint_database.cc.

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

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

Definition at line 721 of file flint_database.cc.

References FlintDatabase::apply(), Assert, cancel(), change_count, DEBUGCALL, DEBUGLINE, doclens, FlintValueTable::encode_values(), flush_postlist_changes(), flush_threshold, freq_deltas, Xapian::Document::get_data(), Xapian::TermIterator::get_wdf(), MAX_SAFE_TERM_LENGTH, mod_plists, FlintDatabase::position_table, Xapian::TermIterator::positionlist_begin(), Xapian::TermIterator::positionlist_end(), FlintDatabase::record_table, FlintRecordTable::replace_record(), RETURN, FlintValueTable::set_encoded_values(), FlintPositionListTable::set_positionlist(), FlintTermListTable::set_termlist(), STRINGIZE, Xapian::Document::termlist_begin(), Xapian::Document::termlist_end(), FlintDatabase::termlist_table, FlintDatabase::total_length, Xapian::Database::Internal::transaction_active(), FlintDatabase::value_table, Xapian::Document::values_begin(), and Xapian::Document::values_end().

Referenced by add_document(), and replace_document().

void FlintWritableDatabase::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 815 of file flint_database.cc.

References FlintDatabase::apply(), Assert, FlintTermList::at_end(), cancel(), change_count, DEBUGCALL, FlintValueTable::delete_all_values(), FlintPositionListTable::delete_positionlist(), FlintRecordTable::delete_record(), FlintTermListTable::delete_termlist(), doclens, flush_postlist_changes(), flush_threshold, freq_deltas, FlintTermList::get_doclength(), FlintTermList::get_termname(), FlintTermList::get_wdf(), mod_plists, FlintTermList::next(), FlintDatabase::position_table, FlintDatabase::record_table, FlintDatabase::termlist_table, FlintDatabase::total_length, Xapian::Database::Internal::transaction_active(), and FlintDatabase::value_table.

void FlintWritableDatabase::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 891 of file flint_database.cc.

References add_document_(), FlintDatabase::apply(), Assert, FlintTermList::at_end(), cancel(), change_count, DEBUGCALL, DEBUGLINE, FlintValueTable::delete_all_values(), FlintPositionListTable::delete_positionlist(), doclens, FlintValueTable::encode_values(), flush_postlist_changes(), flush_threshold, freq_deltas, Xapian::Document::get_data(), FlintTermList::get_doclength(), FlintTermList::get_termname(), Xapian::TermIterator::get_wdf(), FlintTermList::get_wdf(), FlintDatabase::lastdocid, MAX_SAFE_TERM_LENGTH, mod_plists, FlintTermList::next(), FlintDatabase::position_table, Xapian::TermIterator::positionlist_begin(), Xapian::TermIterator::positionlist_end(), FlintDatabase::record_table, FlintRecordTable::replace_record(), FlintValueTable::set_encoded_values(), FlintPositionListTable::set_positionlist(), FlintTermListTable::set_termlist(), STRINGIZE, Xapian::Document::termlist_begin(), Xapian::Document::termlist_end(), FlintDatabase::termlist_table, FlintDatabase::total_length, Xapian::Database::Internal::transaction_active(), FlintDatabase::value_table, Xapian::Document::values_begin(), and Xapian::Document::values_end().

Xapian::doclength FlintWritableDatabase::get_doclength ( Xapian::docid  did  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from FlintDatabase.

Definition at line 1038 of file flint_database.cc.

References DEBUGCALL, doclens, FlintDatabase::get_doclength(), and RETURN.

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

Reimplemented from FlintDatabase.

Definition at line 1048 of file flint_database.cc.

References DEBUGCALL, freq_deltas, FlintDatabase::get_termfreq(), and RETURN.

Referenced by term_exists().

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

Reimplemented from FlintDatabase.

Definition at line 1059 of file flint_database.cc.

References DEBUGCALL, freq_deltas, FlintDatabase::get_collection_freq(), and RETURN.

bool FlintWritableDatabase::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.

Reimplemented from FlintDatabase.

Definition at line 1072 of file flint_database.cc.

References DEBUGCALL, get_termfreq(), and RETURN.

LeafPostList * FlintWritableDatabase::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.

Reimplemented from FlintDatabase.

Definition at line 1079 of file flint_database.cc.

References DEBUGCALL, FlintDatabase::FlintAllDocsPostList, FlintDatabase::FlintPostList, FlintDatabase::get_doccount(), FlintDatabase::lastdocid, mod_plists, and RETURN.

TermList * FlintWritableDatabase::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.

Reimplemented from FlintDatabase.

Definition at line 1104 of file flint_database.cc.

References change_count, DEBUGCALL, flush_postlist_changes(), FlintDatabase::open_allterms(), and RETURN.

void FlintWritableDatabase::add_spelling ( const string &  word,
Xapian::termcount  freqinc 
) const [virtual]

Add a word to the spelling dictionary.

If the word is already present, its frequency is increased.

Parameters:
word The word to add.
freqinc How much to increase its frequency by.

Reimplemented from Xapian::Database::Internal.

Definition at line 1125 of file flint_database.cc.

References FlintSpellingTable::add_word(), and FlintDatabase::spelling_table.

void FlintWritableDatabase::remove_spelling ( const string &  word,
Xapian::termcount  freqdec 
) const [virtual]

Remove a word from the spelling dictionary.

The word's frequency is decreased, and if would become zero or less then the word is removed completely.

Parameters:
word The word to remove.
freqdec How much to decrease its frequency by.

Reimplemented from Xapian::Database::Internal.

Definition at line 1132 of file flint_database.cc.

References FlintSpellingTable::remove_word(), and FlintDatabase::spelling_table.

TermList * FlintWritableDatabase::open_spelling_wordlist (  )  const [virtual]

Return a termlist which returns the words which are spelling correction targets.

If there are no spelling correction targets, returns NULL.

Reimplemented from FlintDatabase.

Definition at line 1139 of file flint_database.cc.

References FlintSpellingTable::merge_changes(), FlintDatabase::open_spelling_wordlist(), and FlintDatabase::spelling_table.

TermList * FlintWritableDatabase::open_synonym_keylist ( const string &  prefix  )  const [virtual]

Open a termlist returning each term which has synonyms.

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

Reimplemented from FlintDatabase.

Definition at line 1146 of file flint_database.cc.

References FlintSynonymTable::merge_changes(), FlintDatabase::open_synonym_keylist(), and FlintDatabase::synonym_table.

void FlintWritableDatabase::add_synonym ( const string &  term,
const string &  synonym 
) const [virtual]

Add a synonym for a term.

If synonym is already a synonym for term, then no action is taken.

Reimplemented from Xapian::Database::Internal.

Definition at line 1153 of file flint_database.cc.

References FlintSynonymTable::add_synonym(), and FlintDatabase::synonym_table.

void FlintWritableDatabase::remove_synonym ( const string &  term,
const string &  synonym 
) const [virtual]

Remove a synonym for a term.

If synonym isn't a synonym for term, then no action is taken.

Reimplemented from Xapian::Database::Internal.

Definition at line 1160 of file flint_database.cc.

References FlintSynonymTable::remove_synonym(), and FlintDatabase::synonym_table.

void FlintWritableDatabase::clear_synonyms ( const string &  term  )  const [virtual]

Clear all synonyms for a term.

If term has no synonyms, no action is taken.

Reimplemented from Xapian::Database::Internal.

Definition at line 1167 of file flint_database.cc.

References FlintSynonymTable::clear_synonyms(), and FlintDatabase::synonym_table.

void FlintWritableDatabase::set_metadata ( const string &  key,
const 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 1173 of file flint_database.cc.

References FlintTable::add(), DEBUGCALL, FlintTable::del(), and FlintDatabase::postlist_table.


Member Data Documentation

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

Unflushed changes to term frequencies and collection frequencies.

Definition at line 263 of file flint_database.h.

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

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

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

Definition at line 266 of file flint_database.h.

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

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

Modifications to posting lists.

Definition at line 270 of file flint_database.h.

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

Xapian::doccount FlintWritableDatabase::change_count [mutable, private]

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

Definition at line 275 of file flint_database.h.

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

Xapian::doccount FlintWritableDatabase::flush_threshold [private]

If change_count reaches this threshold we automatically flush.

Definition at line 278 of file flint_database.h.

Referenced by add_document_(), delete_document(), FlintWritableDatabase(), 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.