xapian-core  1.4.30
Public Member Functions | Private Member Functions | Private Attributes | List of all members
GlassWritableDatabase Class Reference

A writable glass database. More...

#include <glass_database.h>

+ Inheritance diagram for GlassWritableDatabase:
+ Collaboration diagram for GlassWritableDatabase:

Public Member Functions

 GlassWritableDatabase (const string &dir, int flags, int block_size)
 Create and open a writable glass database. More...
 
 ~GlassWritableDatabase ()
 
Xapian::termcount get_doclength (Xapian::docid did) const
 Virtual methods of Database::Internal. More...
 
Xapian::termcount get_unique_terms (Xapian::docid did) const
 Get the number of unique term in document. More...
 
void get_freqs (const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
 Returns frequencies for a term. More...
 
Xapian::doccount get_value_freq (Xapian::valueno slot) const
 Return the frequency of a given value slot. More...
 
std::string get_value_lower_bound (Xapian::valueno slot) const
 Get a lower bound on the values stored in the given value slot. More...
 
std::string get_value_upper_bound (Xapian::valueno slot) const
 Get an upper bound on the values stored in the given value slot. More...
 
bool term_exists (const string &tname) const
 Check whether a given term is in the database. More...
 
bool has_positions () const
 Check whether this database contains any positional information. More...
 
LeafPostListopen_post_list (const string &tname) const
 Open a posting list. More...
 
ValueListopen_value_list (Xapian::valueno slot) const
 Open a value stream. More...
 
void read_position_list (GlassPositionList *pos_list, Xapian::docid did, const string &term) const
 
Xapian::termcount positionlist_count (Xapian::docid did, const string &term) const
 
PositionListopen_position_list (Xapian::docid did, const string &term) const
 Open a position list for the given term in the given document. More...
 
TermListopen_allterms (const string &prefix) const
 Open an allterms list. More...
 
void add_spelling (const string &word, Xapian::termcount freqinc) const
 Add a word to the spelling dictionary. More...
 
void remove_spelling (const string &word, Xapian::termcount freqdec) const
 Remove a word from the spelling dictionary. More...
 
TermListopen_spelling_wordlist () const
 Return a termlist which returns the words which are spelling correction targets. More...
 
TermListopen_synonym_keylist (const string &prefix) const
 Open a termlist returning each term which has synonyms. More...
 
void add_synonym (const string &word, const string &synonym) const
 Add a synonym for a term. More...
 
void remove_synonym (const string &word, const string &synonym) const
 Remove a synonym for a term. More...
 
void clear_synonyms (const string &word) const
 Clear all synonyms for a term. More...
 
void set_metadata (const string &key, const string &value)
 Set the metadata associated with a given key. More...
 
void invalidate_doc_object (Xapian::Document::Internal *obj) const
 Notify the database that document is no longer valid. More...
 
bool has_uncommitted_changes () const
 Return true if there are uncommitted changes. More...
 
- Public Member Functions inherited from GlassDatabase
 GlassDatabase (const string &db_dir_, int flags=Xapian::DB_READONLY_, unsigned int block_size=0u)
 Create and open a glass database. More...
 
 GlassDatabase (int fd)
 
 ~GlassDatabase ()
 
GlassCursorget_postlist_cursor () const
 Get a postlist table cursor (used by GlassValueList). More...
 
glass_revision_number_t get_revision_number () const
 Get an object holding the revision number which the tables are opened at. More...
 
Xapian::doccount get_doccount () const
 Virtual methods of Database::Internal. More...
 
Xapian::docid get_lastdocid () const
 Return the last used document id of this (sub) database. More...
 
Xapian::totallength get_total_length () const
 Return the total length of all documents in this database. More...
 
Xapian::termcount get_doclength_lower_bound () const
 Get a lower bound on the length of a document in this DB. More...
 
Xapian::termcount get_doclength_upper_bound () const
 Get an upper bound on the length of a document in this DB. More...
 
Xapian::termcount get_wdf_upper_bound (const string &term) const
 Get an upper bound on the wdf of term term. More...
 
TermListopen_term_list (Xapian::docid did) const
 Open a term list. More...
 
TermListopen_spelling_termlist (const string &word) const
 Create a termlist tree from trigrams of word. More...
 
Xapian::doccount get_spelling_frequency (const string &word) const
 Return the number of times word was added as a spelling. More...
 
TermListopen_synonym_termlist (const string &term) const
 Open a termlist returning synonyms for a term. More...
 
string get_metadata (const string &key) const
 Get the metadata associated with a given key. More...
 
TermListopen_metadata_keylist (const std::string &prefix) const
 Open a termlist returning each metadata key. More...
 
void write_changesets_to_fd (int fd, const string &start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
 Write a set of changesets to a file descriptor. More...
 
string get_revision_info () const
 Get a string describing the current revision of the database. More...
 
string get_uuid () const
 Get a UUID for the database. More...
 
void request_document (Xapian::docid) const
 Request and later collect a document from the database. More...
 
void readahead_for_query (const Xapian::Query &query)
 
void throw_termlist_table_close_exception () const
 
int get_backend_info (string *path) const
 Get backend information about this database. More...
 
bool single_file () const
 
void get_used_docid_range (Xapian::docid &first, Xapian::docid &last) const
 Find lowest and highest docids actually in use. More...
 
bool locked () const
 Return true if the database is open for writing. More...
 
- Public Member Functions inherited from Xapian::Database::Internal
virtual ~Internal ()
 Destroy the database. More...
 
virtual void keep_alive ()
 Send a keep-alive signal to a remote database, to stop it from timing out. More...
 
void begin_transaction (bool flushed)
 Begin a transaction. More...
 
void commit_transaction ()
 Commit a transaction. More...
 
void cancel_transaction ()
 Cancel a transaction. More...
 
virtual void delete_document (const string &unique_term)
 Delete any documents indexed by a term from the database. More...
 
virtual Xapian::docid replace_document (const string &unique_term, const Xapian::Document &document)
 Replace any documents matching a term. More...
 
virtual Xapian::Document::Internalcollect_document (Xapian::docid did) const
 
- Public Member Functions inherited from Xapian::Internal::intrusive_base
 intrusive_base ()
 Construct with no references. More...
 

Private Member Functions

void check_flush_threshold ()
 Check if we should autoflush. More...
 
void flush_postlist_changes ()
 Flush any unflushed postlist changes, but don't commit them. More...
 
void close ()
 Close all the tables permanently. More...
 
void apply ()
 Apply changes. More...
 
void commit ()
 Implementation of virtual methods: see Database::Internal for details. More...
 
void cancel ()
 Cancel pending modifications to the database. More...
 
Xapian::docid add_document (const Xapian::Document &document)
 Add a new document to the database. More...
 
Xapian::docid add_document_ (Xapian::docid did, const Xapian::Document &document)
 
void delete_document (Xapian::docid did)
 Delete a document in the database. More...
 
void replace_document (Xapian::docid did, const Xapian::Document &document)
 Replace a given document in the database. More...
 
Xapian::Document::Internalopen_document (Xapian::docid did, bool lazy) const
 Open a document. More...
 

Private Attributes

Inverter inverter
 
map< Xapian::valueno, ValueStatsvalue_stats
 
Xapian::doccount change_count
 The number of documents added, deleted, or replaced since the last flush. More...
 
Xapian::doccount flush_threshold
 If change_count reaches this threshold we automatically flush. More...
 
Xapian::Document::Internalmodify_shortcut_document
 A pointer to the last document which was returned by open_document(), or NULL if there is no such valid document. More...
 
Xapian::docid modify_shortcut_docid
 The document ID for the last document returned by open_document(). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GlassDatabase
static void compact (Xapian::Compactor *compactor, const char *destdir, int fd, const std::vector< Xapian::Database::Internal * > &sources, const std::vector< Xapian::docid > &offset, size_t block_size, Xapian::Compactor::compaction_level compaction, unsigned flags, Xapian::docid last_docid)
 
- Public Attributes inherited from Xapian::Internal::intrusive_base
unsigned _refs
 Reference count. More...
 
- Protected Types inherited from Xapian::Database::Internal
enum  { TRANSACTION_UNIMPLEMENTED = -1 , TRANSACTION_NONE = 0 , TRANSACTION_UNFLUSHED = 1 , TRANSACTION_FLUSHED = 2 }
 Transaction state. More...
 
- Protected Member Functions inherited from Xapian::Database::Internal
bool transaction_active () const
 
 Internal ()
 Create a database - called only by derived classes. More...
 
void dtor_called ()
 Internal method to perform cleanup when a writable database is destroyed with uncommitted changes. More...
 
- Protected Attributes inherited from Xapian::Database::Internal
enum Xapian::Database::Internal:: { ... }  transaction_state
 Transaction state. More...
 

Detailed Description

A writable glass database.

Definition at line 332 of file glass_database.h.

Constructor & Destructor Documentation

◆ GlassWritableDatabase()

GlassWritableDatabase::GlassWritableDatabase ( const string &  dir,
int  flags,
int  block_size 
)

Create and open a writable glass database.

Exceptions
Xapian::DatabaseOpeningErrorthrown if database can't be opened.
Xapian::DatabaseVersionErrorthrown if database is in an unsupported format. This implies that the database was created by an older or newer version of Xapian.
Parameters
dirdirectory holding glass tables

Definition at line 1015 of file glass_database.cc.

References flush_threshold, and LOGCALL_CTOR.

◆ ~GlassWritableDatabase()

GlassWritableDatabase::~GlassWritableDatabase ( )

Definition at line 1032 of file glass_database.cc.

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

Member Function Documentation

◆ add_document()

Xapian::docid GlassWritableDatabase::add_document ( const Xapian::Document document)
privatevirtual

Add a new document to the database.

See WritableDatabase::add_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 1096 of file glass_database.cc.

References add_document_(), GlassVersion::get_last_docid(), GlassVersion::get_next_docid(), GLASS_MAX_DOCID, LOGCALL, RETURN, and GlassDatabase::version_file.

◆ add_document_()

Xapian::docid GlassWritableDatabase::add_document_ ( Xapian::docid  did,
const Xapian::Document document 
)
private

◆ add_spelling()

void GlassWritableDatabase::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
wordThe word to add.
freqincHow much to increase its frequency by.

Reimplemented from Xapian::Database::Internal.

Definition at line 1594 of file glass_database.cc.

References GlassSpellingTable::add_word(), and GlassDatabase::spelling_table.

◆ add_synonym()

void GlassWritableDatabase::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 1622 of file glass_database.cc.

References GlassSynonymTable::add_synonym(), and GlassDatabase::synonym_table.

◆ apply()

void GlassWritableDatabase::apply ( )
private

◆ cancel()

void GlassWritableDatabase::cancel ( )
privatevirtual

Cancel pending modifications to the database.

Reimplemented from GlassDatabase.

Definition at line 1585 of file glass_database.cc.

References GlassDatabase::cancel(), change_count, Inverter::clear(), inverter, and value_stats.

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

◆ check_flush_threshold()

void GlassWritableDatabase::check_flush_threshold ( )
private

Check if we should autoflush.

Called at the end of each document changing operation.

Definition at line 1048 of file glass_database.cc.

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

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

◆ clear_synonyms()

void GlassWritableDatabase::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 1636 of file glass_database.cc.

References GlassSynonymTable::clear_synonyms(), and GlassDatabase::synonym_table.

◆ close()

void GlassWritableDatabase::close ( )
privatevirtual

Close all the tables permanently.

Reimplemented from GlassDatabase.

Definition at line 1078 of file glass_database.cc.

References GlassDatabase::close(), commit(), LOGCALL_VOID, and Xapian::Database::Internal::transaction_active().

◆ commit()

void GlassWritableDatabase::commit ( )
privatevirtual

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

Reimplemented from Xapian::Database::Internal.

Definition at line 1039 of file glass_database.cc.

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

Referenced by close().

◆ delete_document()

void GlassWritableDatabase::delete_document ( Xapian::docid  did)
privatevirtual

◆ flush_postlist_changes()

void GlassWritableDatabase::flush_postlist_changes ( )
private

◆ get_doclength()

Xapian::termcount GlassWritableDatabase::get_doclength ( Xapian::docid  did) const
virtual

Virtual methods of Database::Internal.

Reimplemented from GlassDatabase.

Definition at line 1395 of file glass_database.cc.

References GlassDatabase::get_doclength(), Inverter::get_doclength(), inverter, LOGCALL, and RETURN.

Referenced by delete_document().

◆ get_freqs()

void GlassWritableDatabase::get_freqs ( const string &  term,
Xapian::doccount termfreq_ptr,
Xapian::termcount collfreq_ptr 
) const
virtual

Returns frequencies for a term.

Parameters
termThe term to get frequencies for
termfreq_ptrPoint to return number of docs indexed by term (or NULL not to return)
collfreq_ptrPoint to return number of occurrences of term in the database (or NULL not to return)

Reimplemented from GlassDatabase.

Definition at line 1424 of file glass_database.cc.

References Assert, Inverter::get_deltas(), GlassDatabase::get_freqs(), inverter, and LOGCALL_VOID.

Referenced by term_exists().

◆ get_unique_terms()

Xapian::termcount GlassWritableDatabase::get_unique_terms ( Xapian::docid  did) const
virtual

Get the number of unique term in document.

Parameters
didThe document id of the document whose number of terms is being requested.

Reimplemented from GlassDatabase.

Definition at line 1405 of file glass_database.cc.

References Assert, GlassTermList::get_approx_size(), Inverter::get_doclength(), GlassDatabase::get_unique_terms(), inverter, LOGCALL, and RETURN.

◆ get_value_freq()

Xapian::doccount GlassWritableDatabase::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
slotThe value slot to examine.

Reimplemented from GlassDatabase.

Definition at line 1441 of file glass_database.cc.

References GlassDatabase::get_value_freq(), LOGCALL, RETURN, and value_stats.

◆ get_value_lower_bound()

std::string GlassWritableDatabase::get_value_lower_bound ( Xapian::valueno  slot) const
virtual

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.

Parameters
slotThe value slot to examine.

Reimplemented from GlassDatabase.

Definition at line 1451 of file glass_database.cc.

References GlassDatabase::get_value_lower_bound(), LOGCALL, RETURN, and value_stats.

◆ get_value_upper_bound()

std::string GlassWritableDatabase::get_value_upper_bound ( Xapian::valueno  slot) const
virtual

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
slotThe value slot to examine.

Reimplemented from GlassDatabase.

Definition at line 1461 of file glass_database.cc.

References GlassDatabase::get_value_upper_bound(), LOGCALL, RETURN, and value_stats.

◆ has_positions()

bool GlassWritableDatabase::has_positions ( ) const
virtual

Check whether this database contains any positional information.

Reimplemented from GlassDatabase.

Definition at line 1480 of file glass_database.cc.

References Inverter::has_positions(), inverter, and GlassDatabase::position_table.

◆ has_uncommitted_changes()

bool GlassWritableDatabase::has_uncommitted_changes ( ) const
virtual

◆ invalidate_doc_object()

void GlassWritableDatabase::invalidate_doc_object ( Xapian::Document::Internal obj) const
virtual

Notify the database that document is no longer valid.

This is used to invalidate references to a document kept by a database for doing lazy updates. If we moved to using a weak_ptr instead we wouldn't need a special method for this, but it would involve a fair bit of reorganising of other parts of the code.

Reimplemented from Xapian::Database::Internal.

Definition at line 1655 of file glass_database.cc.

References modify_shortcut_docid, and modify_shortcut_document.

◆ open_allterms()

TermList * GlassWritableDatabase::open_allterms ( const string &  prefix) const
virtual

Open an allterms list.

This is a list of all the terms in the database

Parameters
prefixThe 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 GlassDatabase.

Definition at line 1565 of file glass_database.cc.

References change_count, Inverter::flush_post_lists(), inverter, LOGCALL, GlassDatabase::open_allterms(), GlassDatabase::postlist_table, and RETURN.

◆ open_document()

Xapian::Document::Internal * GlassWritableDatabase::open_document ( Xapian::docid  did,
bool  lazy 
) const
privatevirtual

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
didThe document id which is being requested.
lazyNo 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.

Reimplemented from GlassDatabase.

Definition at line 1384 of file glass_database.cc.

References LOGCALL, modify_shortcut_docid, modify_shortcut_document, GlassDatabase::open_document(), and RETURN.

◆ open_position_list()

PositionList * GlassWritableDatabase::open_position_list ( Xapian::docid  did,
const string &  tname 
) const
virtual

Open a position list for the given term in the given document.

Parameters
didThe document id for which a position list is being requested.
tnameThe 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.

Reimplemented from GlassDatabase.

Definition at line 1546 of file glass_database.cc.

References Assert, Inverter::get_positionlist(), inverter, and GlassDatabase::position_table.

◆ open_post_list()

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

Reimplemented from GlassDatabase.

Definition at line 1486 of file glass_database.cc.

References Inverter::flush_doclengths(), Inverter::flush_post_list(), GlassDatabase::get_doccount(), GlassVersion::get_last_docid(), GlassDatabase::GlassAllDocsPostList, GlassDatabase::GlassPostList, inverter, LOGCALL, GlassDatabase::postlist_table, RETURN, and GlassDatabase::version_file.

◆ open_spelling_wordlist()

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

Definition at line 1608 of file glass_database.cc.

References GlassSpellingTable::merge_changes(), GlassDatabase::open_spelling_wordlist(), and GlassDatabase::spelling_table.

◆ open_synonym_keylist()

TermList * GlassWritableDatabase::open_synonym_keylist ( const string &  prefix) const
virtual

Open a termlist returning each term which has synonyms.

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

Reimplemented from GlassDatabase.

Definition at line 1615 of file glass_database.cc.

References GlassSynonymTable::merge_changes(), GlassDatabase::open_synonym_keylist(), and GlassDatabase::synonym_table.

◆ open_value_list()

ValueList * GlassWritableDatabase::open_value_list ( Xapian::valueno  slot) const
virtual

Open a value stream.

This returns the value in a particular slot for each document.

Parameters
slotThe value slot.
Returns
Pointer to a new ValueList object which should be deleted by the caller once it is no longer needed.

Reimplemented from GlassDatabase.

Definition at line 1507 of file glass_database.cc.

References change_count, LOGCALL, GlassValueManager::merge_changes(), GlassDatabase::open_value_list(), RETURN, and GlassDatabase::value_manager.

◆ positionlist_count()

Xapian::termcount GlassWritableDatabase::positionlist_count ( Xapian::docid  did,
const string &  term 
) const
virtual

◆ read_position_list()

void GlassWritableDatabase::read_position_list ( GlassPositionList pos_list,
Xapian::docid  did,
const string &  term 
) const
virtual

◆ remove_spelling()

void GlassWritableDatabase::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
wordThe word to remove.
freqdecHow much to decrease its frequency by.

Reimplemented from Xapian::Database::Internal.

Definition at line 1601 of file glass_database.cc.

References GlassSpellingTable::remove_word(), and GlassDatabase::spelling_table.

◆ remove_synonym()

void GlassWritableDatabase::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 1629 of file glass_database.cc.

References GlassSynonymTable::remove_synonym(), and GlassDatabase::synonym_table.

◆ replace_document()

void GlassWritableDatabase::replace_document ( Xapian::docid  did,
const Xapian::Document document 
)
privatevirtual

◆ set_metadata()

void GlassWritableDatabase::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 1642 of file glass_database.cc.

References GlassTable::add(), GlassTable::del(), LOGCALL_VOID, and GlassDatabase::postlist_table.

◆ term_exists()

bool GlassWritableDatabase::term_exists ( const string &  tname) const
virtual

Check whether a given term is in the database.

Parameters
tnameThe term whose presence is being checked.

Reimplemented from GlassDatabase.

Definition at line 1471 of file glass_database.cc.

References get_freqs(), LOGCALL, and RETURN.

Member Data Documentation

◆ change_count

Xapian::doccount GlassWritableDatabase::change_count
mutableprivate

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

Definition at line 340 of file glass_database.h.

Referenced by cancel(), check_flush_threshold(), commit(), flush_postlist_changes(), has_uncommitted_changes(), open_allterms(), and open_value_list().

◆ flush_threshold

Xapian::doccount GlassWritableDatabase::flush_threshold
private

If change_count reaches this threshold we automatically flush.

Definition at line 343 of file glass_database.h.

Referenced by check_flush_threshold(), and GlassWritableDatabase().

◆ inverter

Inverter GlassWritableDatabase::inverter
mutableprivate

◆ modify_shortcut_docid

Xapian::docid GlassWritableDatabase::modify_shortcut_docid
mutableprivate

The document ID for the last document returned by open_document().

Definition at line 355 of file glass_database.h.

Referenced by delete_document(), invalidate_doc_object(), open_document(), and replace_document().

◆ modify_shortcut_document

Xapian::Document::Internal* GlassWritableDatabase::modify_shortcut_document
mutableprivate

A pointer to the last document which was returned by open_document(), or NULL if there is no such valid document.

This is used purely for comparing with a supplied document to help with optimising replace_document. When the document internals are deleted, this pointer gets set to NULL.

Definition at line 351 of file glass_database.h.

Referenced by delete_document(), invalidate_doc_object(), open_document(), and replace_document().

◆ value_stats

map<Xapian::valueno, ValueStats> GlassWritableDatabase::value_stats
mutableprivate

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