42 #include "../flint_lock.h"
67 #include <sys/types.h>
91 #define MAX_SAFE_TERM_LENGTH 245
106 unsigned int block_size)
108 readonly(flags ==
Xapian::DB_READONLY_),
109 version_file(db_dir),
110 postlist_table(db_dir, readonly),
111 position_table(db_dir, readonly),
112 termlist_table(db_dir, readonly),
113 value_manager(&postlist_table, &termlist_table),
114 synonym_table(db_dir, readonly),
115 spelling_table(db_dir, readonly),
116 record_table(db_dir, readonly),
120 LOGCALL_CTOR(DB,
"ChertDatabase", chert_dir | flags | block_size);
127 int action = flags & Xapian::DB_ACTION_MASK_;
134 if (stat(
db_dir.c_str(), &statbuf) == 0) {
135 if (!
S_ISDIR(statbuf.st_mode)) fail =
true;
136 }
else if (errno != ENOENT || mkdir(
db_dir.c_str(), 0755) == -1) {
151 db_dir +
"': a database already exists and I was told "
152 "not to overwrite it");
183 LOGCALL(DB,
bool,
"ChertDatabase::database_exists", NO_ARGS);
190 LOGCALL_VOID(DB,
"ChertDatabase::create_and_open_tables", NO_ARGS);
218 LOGCALL(DB,
bool,
"ChertDatabase::open_tables_consistent", NO_ARGS);
235 if (cur_rev && cur_rev ==
revision) {
250 bool fully_opened =
false;
252 while (!fully_opened && (tries_left--) > 0) {
343 if (changes_fd < 0) {
344 string message = string(
"Couldn't open changeset ")
350 const char *start = buf;
356 string message = string(
"Changeset at ")
357 + path +
" does not contain valid magic string";
362 unsigned int changes_version;
365 "changeset at " + path);
372 "changeset at " + path);
376 "changeset at " + path);
382 LOGCALL_VOID(DB,
"ChertDatabase::set_revision_number", new_revision);
396 const char *p = getenv(
"XAPIAN_MAX_CHANGESETS");
408 "/changes" +
str(old_revision),
414 FD closefd(changes_fd);
415 if (changes_fd >= 0) {
429 io_write(changes_fd, buf.data(), buf.size());
450 if (changes_fd >= 0) {
451 changes_tail +=
'\0';
457 if (changes_fd >= 0) {
484 const string & term = *t;
493 LOGCALL(DB,
bool,
"ChertDatabase::reopen", NO_ARGS);
514 LOGCALL_VOID(DB,
"ChertDatabase::get_database_write_lock", flags|creating);
520 string msg(
"No chert database found at path '");
533 #ifdef XAPIAN_HAS_REMOTE_BACKEND
544 static const char filenames[] =
545 "\x0b""termlist.DB""\x0e""termlist.baseA\x0e""termlist.baseB"
546 "\x0a""synonym.DB""\x0d""synonym.baseA\x0d""synonym.baseB"
547 "\x0b""spelling.DB""\x0e""spelling.baseA\x0e""spelling.baseB"
548 "\x09""record.DB""\x0c""record.baseA\x0c""record.baseB"
549 "\x0b""position.DB""\x0e""position.baseA\x0e""position.baseB"
550 "\x0b""postlist.DB""\x0e""postlist.baseA\x0e""postlist.baseB"
554 for (
const char * p = filenames; *p; p += *p + 1) {
555 string leaf(p + 1,
size_t(
static_cast<unsigned char>(*p)));
556 filepath.replace(
db_dir.size() + 1, string::npos, leaf);
575 LOGCALL_VOID(DB,
"ChertDatabase::write_changesets_to_fd", fd |
revision | need_whole_db | info);
576 #ifdef XAPIAN_HAS_REMOTE_BACKEND
583 const char * rev_ptr =
revision.data();
584 const char * rev_end = rev_ptr +
revision.size();
585 if (!
unpack_uint(&rev_ptr, rev_end, &start_rev_num)) {
586 need_whole_db =
true;
602 if (whole_db_copies_left == 0) {
604 "Database changing too fast",
608 whole_db_copies_left--;
618 need_whole_db =
false;
630 if (info != NULL && start_rev_num == needed_rev_num)
644 need_whole_db =
true;
651 need_whole_db =
true;
660 string changes_name =
db_dir +
"/changes" +
str(start_rev_num);
662 if (fd_changes >= 0) {
668 &changeset_start_rev_num,
669 &changeset_end_rev_num);
670 if (changeset_start_rev_num != start_rev_num) {
673 if (changeset_start_rev_num >= changeset_end_rev_num) {
678 start_rev_num = changeset_end_rev_num;
681 if (start_rev_num >= needed_rev_num)
687 need_whole_db =
true;
703 const std::string & msg)
723 "), and cannot set consistent table "
724 "revision numbers: " + e.
get_msg());
820 LOGCALL_VOID(DB,
"ChertDatabase::get_freqs", term | termfreq_ptr | collfreq_ptr);
835 LOGCALL(DB, std::string,
"ChertDatabase::get_value_lower_bound", slot);
842 LOGCALL(DB, std::string,
"ChertDatabase::get_value_upper_bound", slot);
869 LOGCALL(DB,
bool,
"ChertDatabase::term_exists", term);
942 return poslist.release();
963 if (!cursor)
return NULL;
984 if (!cursor)
return NULL;
992 LOGCALL(DB,
string,
"ChertDatabase::get_metadata", key);
993 string btree_key(
"\x00\xc0", 2);
1003 LOGCALL(DB,
TermList *,
"ChertDatabase::open_metadata_keylist", NO_ARGS);
1005 if (!cursor)
RETURN(NULL);
1013 LOGCALL(DB,
string,
"ChertDatabase::get_revision_info", NO_ARGS);
1022 LOGCALL(DB,
string,
"ChertDatabase::get_uuid", NO_ARGS);
1071 modify_shortcut_document(NULL),
1072 modify_shortcut_docid(0)
1074 LOGCALL_CTOR(DB,
"ChertWritableDatabase", dir | action | block_size);
1076 const char *p = getenv(
"XAPIAN_FLUSH_THRESHOLD");
1132 LOGCALL_VOID(DB,
"ChertWritableDatabase::close", NO_ARGS);
1152 map<string, pair<termcount_diff, termcount_diff> >::iterator i;
1155 freq_deltas.insert(make_pair(tname, make_pair(tf_delta, cf_delta)));
1157 i->second.first += tf_delta;
1158 i->second.second += cf_delta;
1164 const string & tname,
1168 map<string, map<docid, pair<char, termcount> > >::iterator j;
1171 map<docid, pair<char, termcount> > m;
1172 j =
mod_plists.insert(make_pair(tname, m)).first;
1174 j->second[did] = make_pair(
'A', wdf);
1179 const string & tname,
1184 map<string, map<docid, pair<char, termcount> > >::iterator j;
1187 map<docid, pair<char, termcount> > m;
1188 j =
mod_plists.insert(make_pair(tname, m)).first;
1191 map<docid, pair<char, termcount> >::iterator k;
1192 k = j->second.find(did);
1193 if (k == j->second.end()) {
1194 j->second.insert(make_pair(did, make_pair(type, wdf)));
1198 Assert(k->second.first ==
'D');
1201 k->second = make_pair(type, wdf);
1211 throw Xapian::DatabaseError(
"Run out of docids - you'll have to use copydatabase to eliminate any gaps before you can add more documents");
1238 string tname = *term;
1252 LOGLINE(DB,
"Calculated doclen for new document " << did <<
" as " << new_doclen);
1279 LOGCALL_VOID(DB,
"ChertWritableDatabase::delete_document", did);
1308 while (!termlist.
at_end()) {
1341 LOGCALL_VOID(DB,
"ChertWritableDatabase::replace_document", did | document);
1365 bool modifying =
false;
1372 if (!document.
internal->modified()) {
1377 LOGLINE(DB,
"Detected potential document modification shortcut.");
1387 if (!modifying || document.
internal->terms_modified()) {
1388 bool pos_modified = !modifying ||
1389 document.
internal->term_positions_modified();
1397 string old_tname, new_tname;
1409 cmp = old_tname.compare(new_tname);
1418 new_doclen -= old_wdf;
1424 }
else if (cmp > 0) {
1427 new_doclen += new_wdf;
1442 }
else if (cmp == 0) {
1452 if (old_wdf != new_wdf) {
1453 new_doclen += new_wdf - old_wdf;
1473 LOGLINE(DB,
"Calculated doclen for replacement document " << did <<
" as " << new_doclen);
1480 if (new_doclen != old_doclen)
1485 if (!modifying || document.
internal->data_modified()) {
1490 if (!modifying || document.
internal->values_modified()) {
1524 map<docid, termcount>::const_iterator i =
doclens.find(did);
1545 map<docid, termcount>::const_iterator i =
doclens.find(did);
1563 LOGCALL_VOID(DB,
"ChertWritableDatabase::get_freqs", term | termfreq_ptr | collfreq_ptr);
1566 map<string, pair<termcount_diff, termcount_diff> >::const_iterator i;
1570 *termfreq_ptr += i->second.first;
1572 *collfreq_ptr += i->second.second;
1580 map<Xapian::valueno, ValueStats>::const_iterator i;
1589 LOGCALL(DB, std::string,
"ChertWritableDatabase::get_value_lower_bound", slot);
1590 map<Xapian::valueno, ValueStats>::const_iterator i;
1599 LOGCALL(DB, std::string,
"ChertWritableDatabase::get_value_upper_bound", slot);
1600 map<Xapian::valueno, ValueStats>::const_iterator i;
1609 LOGCALL(DB,
bool,
"ChertWritableDatabase::term_exists", tname);
1621 if (tname.empty()) {
1632 map<string, map<docid, pair<char, termcount> > >::const_iterator j;
1658 LOGCALL(DB,
TermList *,
"ChertWritableDatabase::open_allterms", NO_ARGS);
1708 const string & synonym)
const
1715 const string & synonym)
const
1729 LOGCALL_VOID(DB,
"ChertWritableDatabase::set_metadata", key | value);
1730 string btree_key(
"\x00\xc0", 2);
1732 if (value.empty()) {
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
Wrapper around standard unique_ptr template.
A ChertAllDocsPostList plus pending modifications.
A PostList which iterates over all documents in a ChertDatabase.
A termlist containing all terms in a chert database.
const int MAX_OPEN_RETRIES
Maximum number of times to try opening the tables to get them at a consistent revision.
#define MAX_SAFE_TERM_LENGTH
C++ class definition for chert database.
A document read from a ChertDatabase.
A ChertPostList plus pending modifications.
A position list in a chert database.
Postlists in chert databases.
Records in chert databases.
Internal definitions for chert database replication.
#define CHANGES_MAGIC_STRING
#define REASONABLE_CHANGESET_SIZE
A termlist containing all words which are spelling targets.
A TermList in a chert database.
unsigned int chert_doclen_t
An integer type for storing the length of a document - ie, the sum of the wdfs of the terms in the do...
#define CHERT_MAX_DOCID
The largest docid value supported by chert.
unsigned int chert_revision_number_t
A type used to store a revision number for a table.
Chert class for value streams.
A cursor pointing to a position in a Btree table, for reading several entries in order,...
Xapian::termcount get_wdf_upper_bound() const
Xapian::termcount get_doclength_upper_bound() const
void delete_document(Xapian::termcount doclen)
void read(ChertPostListTable &postlist_table)
Xapian::totallength get_total_doclen() const
Xapian::docid get_last_docid() const
void check_wdf(Xapian::termcount wdf)
void write(ChertPostListTable &postlist_table) const
Xapian::termcount get_doclength_lower_bound() const
void add_document(Xapian::termcount doclen)
void set_last_docid(Xapian::docid did)
Xapian::docid get_next_docid()
A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree s...
bool readonly
Whether the database is readonly.
friend class ChertAllDocsPostList
ChertTermListTable termlist_table
Table storing term lists.
Xapian::docid get_lastdocid() const
Return the last used document id of this (sub) database.
TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
void get_database_write_lock(int flags, bool creating)
Get a write lock on the database, or throw an Xapian::DatabaseLockError if failure.
std::string db_dir
Directory to store databases in.
Xapian::doccount get_doccount() const
Virtual methods of Database::Internal.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
void open_tables(chert_revision_number_t revision)
Open tables at specified revision number.
ChertValueManager value_manager
Value manager.
PositionList * open_position_list(Xapian::docid did, const string &term) const
Open a position list for the given term in the given document.
chert_revision_number_t get_next_revision_number() const
Get an object holding the next revision number which should be used in the tables.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
Find lowest and highest docids actually in use.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
void set_revision_number(chert_revision_number_t new_revision)
Set the revision number in the tables.
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.
unsigned int max_changesets
The maximum number of changesets which should be kept in the database.
void get_changeset_revisions(const string &path, chert_revision_number_t *startrev, chert_revision_number_t *endrev) const
Get the revision stored in a changeset.
bool term_exists(const string &tname) const
Check whether a given term is in the database.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
ChertDatabase(const string &db_dir_, int action=Xapian::DB_READONLY_, unsigned int block_size=0u)
Create and open a chert database.
TermList * open_allterms(const string &prefix) const
Open an allterms list.
void apply()
Apply any outstanding changes to the tables.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Open a document.
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
TermList * open_synonym_termlist(const string &term) const
Open a termlist returning synonyms for a term.
TermList * open_spelling_termlist(const string &word) const
Create a termlist tree from trigrams of word.
TermList * open_term_list(Xapian::docid did) const
Open a term list.
ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
FlintLock lock
Lock object.
void close()
Close all the tables permanently.
virtual bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
friend class ChertTermList
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a given document.
void request_document(Xapian::docid) const
Request and later collect a document from the database.
bool open_tables_consistent()
Open all tables at most recent consistent revision.
void cancel()
Cancel any outstanding changes to the tables.
string get_metadata(const string &key) const
Get the metadata associated with a given key.
string get_uuid() const
Get a UUID for the database.
TermList * open_metadata_keylist(const std::string &prefix) const
Open a termlist returning each metadata key.
ChertSynonymTable synonym_table
Table storing synonym data.
void readahead_for_query(const Xapian::Query &query)
void send_whole_database(RemoteConnection &conn, double end_time)
Send a set of messages which transfer the whole database.
bool database_exists()
Return true if a database exists at the path specified for this database.
ChertPostListTable postlist_table
Table storing posting lists.
Xapian::doccount get_spelling_frequency(const string &word) const
Return the number of times word was added as a spelling.
bool has_positions() const
Check whether this database contains any positional information.
void create_and_open_tables(unsigned int blocksize)
Create new tables, and open them.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
ChertPositionListTable position_table
Table storing position lists.
bool locked() const
Return true if the database is open for writing.
friend class ChertAllTermsList
ChertVersion version_file
The file describing the Chert database.
bool reopen()
Re-open tables to recover from an overwritten condition, or just get most up-to-date version.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique term in document.
string get_revision_info() const
Get a string describing the current revision of the database.
LeafPostList * open_post_list(const string &tname) const
Open a posting list.
void throw_termlist_table_close_exception() const
chert_revision_number_t get_revision_number() const
Get an object holding the revision number which the tables are opened at.
ChertRecordTable record_table
Table storing records.
ChertSpellingTable spelling_table
Table storing spelling correction data.
TermList * open_synonym_keylist(const string &prefix) const
Open a termlist returning each term which has synonyms.
friend class ChertPostList
ChertDatabaseStats stats
Database statistics.
Xapian::termcount get_wdf_upper_bound(const string &term) const
Get an upper bound on the wdf of term term.
void modifications_failed(chert_revision_number_t old_revision, chert_revision_number_t new_revision, const std::string &msg)
Called if a modifications fail.
friend class ChertWritableDatabase
A document read from a ChertDatabase.
void create_and_open(unsigned int blocksize)
Lazy version of ChertTable::create_and_open().
void delete_positionlist(Xapian::docid did, const string &tname)
Delete the position list for term tname in document did.
void set_positionlist(Xapian::docid did, const string &tname, Xapian::PositionIterator pos, const Xapian::PositionIterator &pos_end, bool check_for_update)
Set the position list for term tname in document did.
A position list in a chert database.
Xapian::termcount get_doclength(Xapian::docid did, Xapian::Internal::intrusive_ptr< const ChertDatabase > db) const
Returns the length of document did.
bool document_exists(Xapian::docid did, Xapian::Internal::intrusive_ptr< const ChertDatabase > db) const
Check if document did exists.
bool open(chert_revision_number_t revno)
static string make_key(const string &term, Xapian::docid did)
Compose a key from a termname and docid.
bool term_exists(const string &term) const
void merge_changes(const map< string, map< Xapian::docid, pair< char, Xapian::termcount > > > &mod_plists, const map< Xapian::docid, Xapian::termcount > &doclens, const map< string, pair< Xapian::termcount_diff, Xapian::termcount_diff > > &freq_deltas)
Merge added, removed, and changed entries.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
void get_freqs(const std::string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void readahead_for_record(Xapian::docid did) const
void delete_record(Xapian::docid did)
Delete a record from the table.
Xapian::doccount get_doccount() const
Get the number of records in the table.
void replace_record(const string &data, Xapian::docid did)
void cancel()
Override methods of ChertTable.
TermList * open_termlist(const std::string &word)
void flush_db()
Override methods of ChertTable.
Xapian::doccount get_word_frequency(const std::string &word) const
void remove_word(const std::string &word, Xapian::termcount freqdec)
bool is_modified() const
Override methods of ChertTable.
void add_word(const std::string &word, Xapian::termcount freqinc)
void remove_synonym(const std::string &term, const std::string &synonym)
Remove a synonym for term.
void clear_synonyms(const std::string &term)
Remove all synonyms for term.
void flush_db()
Override methods of ChertTable.
void cancel()
Override methods of ChertTable.
TermList * open_termlist(const std::string &term)
Open synonym termlist for a term.
void add_synonym(const std::string &term, const std::string &synonym)
Add a synonym for term.
bool is_modified() const
Override methods of ChertTable.
void open()
Open the btree at the latest revision.
ChertCursor * cursor_get() const
Get a cursor for reading from the table.
bool readahead_key(const string &key) const
unsigned int get_block_size() const
Get the block size.
void commit(chert_revision_number_t revision, int changes_fd=-1, const std::string *changes_tail=NULL)
Commit any outstanding changes to the table.
void set_block_size(unsigned int block_size_)
Set the block size.
static void throw_database_closed()
Throw an exception indicating that the database is closed.
void flush_db()
Flush any outstanding changes to the DB file of the table.
bool get_exact_entry(const std::string &key, std::string &tag) const
Read an entry from the table, if and only if it is exactly that being asked for.
bool empty() const
Return true if there are no entries in the table.
bool del(const std::string &key)
Delete an entry from the table.
bool is_open() const
Return true if this table is open.
void write_changed_blocks(int changes_fd)
Append the list of blocks changed to a changeset file.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
chert_revision_number_t get_open_revision_number() const
Get the revision number at which this table is currently open.
bool exists() const
Determine whether the btree exists on disk.
void cancel()
Cancel any outstanding changes.
void add(const std::string &key, std::string tag, bool already_compressed=false)
Add a key/tag pair to the table, replacing any existing pair with the same key.
void create_and_open(unsigned int blocksize)
Create a new empty btree structure on disk and open it at the initial revision.
void close(bool permanent=false)
Close the Btree.
chert_revision_number_t get_latest_revision_number() const
Get the latest revision number stored in this table.
void set_termlist(Xapian::docid did, const Xapian::Document &doc, chert_doclen_t doclen)
Set the termlist data for document did.
void create_and_open(unsigned int blocksize)
Non-lazy override of ChertLazyTable::create_and_open().
void delete_termlist(Xapian::docid did)
Delete the termlist data for document did.
A TermList in a chert database.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
chert_doclen_t get_doclength() const
Return the length of this document.
bool at_end() const
Return true if the current position is past the last term in this list.
std::string get_termname() const
Return the termname at the current position.
TermList * next()
Advance the current position to the next term in the termlist.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Chert class for value streams.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
void set_value_stats(std::map< Xapian::valueno, ValueStats > &value_stats)
Write the updated statistics to the table.
std::string get_value_lower_bound(Xapian::valueno slot) const
void delete_document(Xapian::docid did, std::map< Xapian::valueno, ValueStats > &value_stats)
void add_document(Xapian::docid did, const Xapian::Document &doc, std::map< Xapian::valueno, ValueStats > &value_stats)
void replace_document(Xapian::docid did, const Xapian::Document &doc, std::map< Xapian::valueno, ValueStats > &value_stats)
std::string get_value_upper_bound(Xapian::valueno slot) const
void read_and_check()
Read the version file and check it's a version we understand.
std::string get_uuid_string() const
Return UUID in the standard 36 character string format.
void create()
Create the version file.
TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
map< Xapian::docid, Xapian::termcount > doclens
Document lengths of new and modified documents which haven't been flushed yet.
void check_flush_threshold()
Check if we should autoflush.
void add_spelling(const string &word, Xapian::termcount freqinc) const
Add a word to the spelling dictionary.
Xapian::doccount flush_threshold
If change_count reaches this threshold we automatically flush.
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
void clear_synonyms(const string &word) const
Clear all synonyms for a term.
map< string, pair< Xapian::termcount_diff, Xapian::termcount_diff > > freq_deltas
Unflushed changes to term frequencies and collection frequencies.
void cancel()
Cancel pending modifications to the database.
Xapian::Document::Internal * modify_shortcut_document
A pointer to the last document which was returned by open_document(), or NULL if there is no such val...
bool term_exists(const string &tname) const
Check whether a given term is in the database.
Xapian::docid add_document_(Xapian::docid did, const Xapian::Document &document)
map< string, map< Xapian::docid, pair< char, Xapian::termcount > > > mod_plists
Modifications to posting lists.
void update_mod_plist(Xapian::docid did, const string &tname, char type, Xapian::termcount wdf)
Update the stored modifications to the postlists.
void flush_postlist_changes() const
Flush any unflushed postlist changes, but don't commit them.
void invalidate_doc_object(Xapian::Document::Internal *obj) const
Notify the database that document is no longer valid.
void insert_mod_plist(Xapian::docid did, const string &tname, Xapian::termcount wdf)
Insert modifications for a new document to the postlists.
void add_freq_delta(const string &tname, Xapian::termcount_diff tf_delta, Xapian::termcount_diff cf_delta)
Add or modify an entry in freq_deltas.
ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Open a document.
bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
void add_synonym(const string &word, const string &synonym) const
Add a synonym for a term.
void remove_spelling(const string &word, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique term in document.
void apply()
Apply changes.
map< Xapian::valueno, ValueStats > value_stats
Xapian::termcount get_doclength(Xapian::docid did) const
Virtual methods of Database::Internal.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
TermList * open_allterms(const string &prefix) const
Open an allterms list.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void commit()
Implementation of virtual methods: see Database::Internal for details.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
void set_metadata(const string &key, const string &value)
Set the metadata associated with a given key.
Xapian::docid modify_shortcut_docid
The document ID for the last document returned by open_document().
TermList * open_synonym_keylist(const string &prefix) const
Open a termlist returning each term which has synonyms.
void close()
Close all the tables permanently.
void remove_synonym(const string &word, const string &synonym) const
Remove a synonym for a term.
Xapian::doccount change_count
The number of documents added, deleted, or replaced since the last flush.
LeafPostList * open_post_list(const string &tname) const
Open a posting list.
void delete_document(Xapian::docid did)
Delete a document in the database.
A PostList iterating all docids when they form a contiguous range.
void release()
Release the lock.
reason lock(bool exclusive, bool wait, std::string &explanation)
Attempt to obtain the lock.
bool test() const
Test if the lock is held.
void throw_databaselockerror(FlintLock::reason why, const std::string &db_dir, const std::string &explanation) const
Throw Xapian::DatabaseLockError.
Abstract base class for leaf postlists.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
void send_message(char type, const std::string &s, double end_time)
Send a message.
void send_file(char type, int fd, double end_time)
Send the contents of a file as a message.
DatabaseCorruptError indicates database corruption was detected.
DatabaseCreateError indicates a failure to create a database.
DatabaseError indicates some sort of database related error.
DatabaseModifiedError indicates a database was modified.
Indicates an attempt to access a database not present.
void dtor_called()
Internal method to perform cleanup when a writable database is destroyed with uncommitted changes.
bool transaction_active() const
Indicates an attempt to access a document not present in the database.
A document in the database, possibly plus modifications.
A handle representing a document in a Xapian database.
std::string get_data() const
Get data stored in the document.
TermIterator termlist_end() const
Equivalent end iterator for termlist_begin().
TermIterator termlist_begin() const
Start iterating the terms in this document.
Xapian::Internal::intrusive_ptr< Internal > internal
All exceptions thrown by Xapian are subclasses of Xapian::Error.
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
std::string get_description() const
Return a string describing this object.
Indicates an attempt to use a feature which is unavailable.
A smart pointer that uses intrusive reference counting.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
InvalidOperationError indicates the API was used in an invalid way.
Abstract base class for iterating term positions in a document.
Class for iterating over term positions.
Class representing a query.
const TermIterator get_unique_terms_begin() const
Begin iterator for unique terms in the query object.
Abstract base class for termlists.
Class for iterating over a list of terms.
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
Abstract base class for value streams.
Constants in the Xapian namespace.
Iterate all document ids when they form a contiguous range.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
#define LOGCALL_DTOR(CATEGORY, CLASS)
Hierarchy of classes which Xapian can throw as exceptions.
Wrapper class around a file descriptor to avoid leaks.
bool io_unlink(const std::string &filename)
Delete a file.
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
size_t io_read(int fd, char *p, size_t n, size_t min)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
Wrappers for low-level POSIX I/O routines.
length encoded as a string
std::string encode_length(T len)
Encode a length as a variable-length string.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
string str(int value)
Convert int to std::string.
The Xapian namespace contains public interfaces for the Xapian library.
const int DB_CREATE
Create a new database.
int revision()
Report the revision of the library which the program is linked with.
const int DB_RETRY_LOCK
If the database is already locked, retry the lock.
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DB_OPEN
Open an existing database.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
const int DB_CREATE_OR_OVERWRITE
Create database if it doesn't already exist, or overwrite if it does.
Pack types into strings and unpack them again.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
Provides wrappers with POSIXy semantics.
RemoteConnection class used by the remote backend.
int create_changeset_file(const string &changeset_dir, const string &filename, string &changes_name)
Create a new changeset file, and return an open fd for writing to it.
Utility functions for replication implementations.
Replication support for Xapian databases.
Replication protocol version and message numbers.
#define MAX_DB_COPIES_PER_CONVERSATION
@ REPL_REPLY_END_OF_CHANGES
include <sys/stat.h> with portability enhancements
Convert types to std::string.
Various handy helpers which std::string really should provide.
#define CONST_STRLEN(S)
Returns the length of a string constant.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
Information about the steps involved in performing a replication.
bool changed
True if and only if the replication corresponds to a change in the live version of the database.
int fullcopy_count
Number of times a full database copy was performed.
int changeset_count
Number of changesets applied.
Class for iterating over document values.