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) {
274 if (revision == newrevision) {
280 revision = newrevision;
295 LOGCALL_VOID(DB,
"ChertDatabase::open_tables", revision);
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 '");
532 LOGCALL_VOID(DB,
"ChertDatabase::send_whole_database", conn | end_time);
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);
1527 if (doclen == static_cast<Xapian::termcount>(-1)) {
1545 map<docid, termcount>::const_iterator i =
doclens.find(did);
1548 if (doclen == static_cast<Xapian::termcount>(-1)) {
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()) {
bool term_exists(const string &tname) const
Virtual methods of Database::Internal.
bool is_modified() const
Override methods of ChertTable.
void delete_termlist(Xapian::docid did)
Delete the termlist data for document did.
Xapian::docid get_lastdocid() const
Virtual methods of Database::Internal.
TermList * open_spelling_termlist(const string &word) const
Virtual methods of Database::Internal.
The Xapian namespace contains public interfaces for the Xapian library.
A PostList which iterates over all documents in a ChertDatabase.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Virtual methods of Database::Internal.
void throw_databaselockerror(FlintLock::reason why, const std::string &db_dir, const std::string &explanation) const
Throw Xapian::DatabaseLockError.
bool term_exists(const string &term) const
Xapian::termcount get_wdf_upper_bound() const
A TermList in a chert database.
void release()
Release the lock.
void set_metadata(const string &key, const string &value)
Virtual methods of Database::Internal.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
A position list in a chert database.
RemoteConnection class used by the remote backend.
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
unsigned int get_block_size() const
Get the block size.
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Xapian::termcount get_doclength_upper_bound() const
Records in chert databases.
virtual bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
Xapian::termcount get_doclength(Xapian::docid did, Xapian::Internal::intrusive_ptr< const ChertDatabase > db) const
Returns the length of document did.
length encoded as a string
void read_and_check()
Read the version file and check it's a version we understand.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
void set_termlist(Xapian::docid did, const Xapian::Document &doc, chert_doclen_t doclen)
Set the termlist data for document did.
Xapian::termcount get_wdf_upper_bound(const string &term) const
Virtual methods of Database::Internal.
bool io_unlink(const std::string &filename)
Delete a file.
std::string get_value_upper_bound(Xapian::valueno slot) const
Virtual methods of Database::Internal.
void get_database_write_lock(int flags, bool creating)
Get a write lock on the database, or throw an Xapian::DatabaseLockError if failure.
LeafPostList * open_post_list(const string &tname) const
Virtual methods of Database::Internal.
Chert class for value streams.
A PostList iterating all docids when they form a contiguous range.
void clear_synonyms(const std::string &term)
Remove all synonyms for term.
void readahead_for_query(const Xapian::Query &query)
Virtual methods of Database::Internal.
int fullcopy_count
Number of times a full database copy was performed.
void add_document(Xapian::docid did, const Xapian::Document &doc, std::map< Xapian::valueno, ValueStats > &value_stats)
const int DB_CREATE
Create a new database.
bool database_exists()
Return true if a database exists at the path specified for this database.
InvalidOperationError indicates the API was used in an invalid way.
bool transaction_active() const
A document read from a ChertDatabase.
bool open(chert_revision_number_t revno)
TermList * open_synonym_termlist(const string &term) const
Virtual methods of Database::Internal.
Xapian::termcount get_doclength_upper_bound() const
Virtual methods of Database::Internal.
A document read from a ChertDatabase.
Xapian::totallength get_total_doclen() const
void write_changesets_to_fd(int fd, const string &start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
Virtual methods of Database::Internal.
map< Xapian::docid, Xapian::termcount > doclens
Document lengths of new and modified documents which haven't been flushed yet.
Xapian::termcount get_doclength(Xapian::docid did) const
Virtual methods of Database::Internal.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
Find lowest and highest docids actually in use.
ChertRecordTable record_table
Table storing records.
void cancel()
Cancel any outstanding changes to the tables.
TermList * open_synonym_keylist(const string &prefix) const
Virtual methods of Database::Internal.
Iterate all document ids when they form a contiguous range.
void add_spelling(const string &word, Xapian::termcount freqinc) const
Virtual methods of Database::Internal.
void flush_postlist_changes() const
Flush any unflushed postlist changes, but don't commit them.
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Xapian::doccount get_doccount() const
Virtual methods of Database::Internal.
const int MAX_OPEN_RETRIES
Maximum number of times to try opening the tables to get them at a consistent revision.
void set_value_stats(std::map< Xapian::valueno, ValueStats > &value_stats)
Write the updated statistics to the table.
std::string get_value_upper_bound(Xapian::valueno slot) const
Provides wrappers with POSIXy semantics.
bool open_tables_consistent()
Open all tables at most recent consistent revision.
Constants in the Xapian namespace.
Internal definitions for chert database replication.
void send_file(char type, int fd, double end_time)
Send the contents of a file as a message.
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
#define LOGCALL_DTOR(CATEGORY, CLASS)
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Implementation of virtual methods: see Database::Internal for details.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
friend class ChertTermList
ChertSpellingTable spelling_table
Table storing spelling correction data.
A document in the database, possibly plus modifications.
TermList * open_allterms(const string &prefix) const
Virtual methods of Database::Internal.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
chert_revision_number_t get_revision_number() const
Get an object holding the revision number which the tables are opened at.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
void remove_spelling(const string &word, Xapian::termcount freqdec) const
Virtual methods of Database::Internal.
Abstract base class for termlists.
Xapian::docid get_next_docid()
Convert types to std::string.
void set_revision_number(chert_revision_number_t new_revision)
Set the revision number in the tables.
ChertVersion version_file
The file describing the Chert database.
bool is_open() const
Return true if this table is open.
ChertPositionListTable position_table
Table storing position lists.
TermList * open_synonym_keylist(const string &prefix) const
Virtual methods of Database::Internal.
int revision()
Report the revision of the library which the program is linked with.
void open()
Open the btree at the latest revision.
Abstract base class for leaf postlists.
void get_freqs(const std::string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void close()
Close all the tables permanently.
ChertPostListTable postlist_table
Table storing posting lists.
PositionList * open_position_list(Xapian::docid did, const string &term) const
Virtual methods of Database::Internal.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Implementation of virtual methods: see Database::Internal for details.
std::string encode_length(T len)
Encode a length as a variable-length string.
void replace_record(const string &data, Xapian::docid did)
TermIterator termlist_end() const
Equivalent end iterator for termlist_begin().
void check_flush_threshold()
Check if we should autoflush.
ChertSynonymTable synonym_table
Table storing synonym data.
TermList * open_termlist(const std::string &term)
Open synonym termlist for a term.
bool test() const
Test if the lock is held.
Xapian::doccount get_word_frequency(const std::string &word) const
void invalidate_doc_object(Xapian::Document::Internal *obj) const
Virtual methods of Database::Internal.
include <sys/stat.h> with portability enhancements
const TermIterator get_unique_terms_begin() const
Begin iterator for unique terms in the query object.
void create_and_open_tables(unsigned int blocksize)
Create new tables, and open them.
void add_synonym(const string &word, const string &synonym) const
Virtual methods of Database::Internal.
bool exists() const
Determine whether the btree exists on disk.
FlintLock lock
Lock object.
void create_and_open(unsigned int blocksize)
Create a new empty btree structure on disk and open it at the initial revision.
bool has_positions() const
Virtual methods of Database::Internal.
void insert_mod_plist(Xapian::docid did, const string &tname, Xapian::termcount wdf)
Insert modifications for a new document to the postlists.
unsigned int chert_revision_number_t
A type used to store a revision number for a table.
Xapian::doccount get_spelling_frequency(const string &word) const
Virtual methods of Database::Internal.
ChertWritableDatabase(const string &dir, int action, int block_size)
Create and open a writable chert database.
Xapian::docid modify_shortcut_docid
The document ID for the last document returned by open_document().
#define MAX_SAFE_TERM_LENGTH
bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
std::string get_uuid_string() const
Return UUID in the standard 36 character string format.
Xapian::docid get_last_docid() const
#define REASONABLE_CHANGESET_SIZE
void apply()
Apply changes.
#define CHANGES_MAGIC_STRING
ValueList * open_value_list(Xapian::valueno slot) const
Virtual methods of Database::Internal.
Hierarchy of classes which Xapian can throw as exceptions.
bool readahead_key(const string &key) const
Xapian::termcount get_unique_terms(Xapian::docid did) const
Virtual methods of Database::Internal.
Class for iterating over a list of terms.
bool del(const std::string &key)
Delete an entry from the table.
void delete_document(Xapian::termcount doclen)
std::string get_termname() const
Return the termname at the current position.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
void update_mod_plist(Xapian::docid did, const string &tname, char type, Xapian::termcount wdf)
Update the stored modifications to the postlists.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Virtual methods of Database::Internal.
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
std::string get_value_upper_bound(Xapian::valueno slot) const
Virtual methods of Database::Internal.
friend class ChertPostList
void read(ChertPostListTable &postlist_table)
void add_synonym(const std::string &term, const std::string &synonym)
Add a synonym for term.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
std::string get_value_lower_bound(Xapian::valueno slot) const
Virtual methods of Database::Internal.
Xapian::docid add_document_(Xapian::docid did, const Xapian::Document &document)
Implementation of virtual methods: see Database::Internal for details.
TermList * open_termlist(const std::string &word)
void commit()
Implementation of virtual methods: see Database::Internal for details.
void delete_record(Xapian::docid did)
Delete a record from the table.
void send_whole_database(RemoteConnection &conn, double end_time)
Send a set of messages which transfer the whole database.
bool reopen()
Re-open tables to recover from an overwritten condition, or just get most up-to-date version...
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.
bool at_end() const
Return true if the current position is past the last term in this list.
chert_revision_number_t get_open_revision_number() const
Get the revision number at which this table is currently open.
DatabaseModifiedError indicates a database was modified.
friend class ChertAllTermsList
void cancel()
Cancel any outstanding changes.
std::string get_value_lower_bound(Xapian::valueno slot) const
Virtual methods of Database::Internal.
const int DB_OPEN
Open an existing database.
ValueList * open_value_list(Xapian::valueno slot) const
Virtual methods of Database::Internal.
void delete_document(Xapian::docid did)
Implementation of virtual methods: see Database::Internal for details.
Indicates an attempt to use a feature which is unavailable.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
std::string db_dir
Directory to store databases in.
void create_and_open(unsigned int blocksize)
Non-lazy override of ChertLazyTable::create_and_open().
ChertValueManager value_manager
Value manager.
map< string, map< Xapian::docid, pair< char, Xapian::termcount > > > mod_plists
Modifications to posting lists.
void clear_synonyms(const string &word) const
Virtual methods of Database::Internal.
string get_revision_info() const
Virtual methods of Database::Internal.
TermList * open_spelling_wordlist() const
Virtual methods of Database::Internal.
string get_uuid() const
Virtual methods of Database::Internal.
DatabaseCreateError indicates a failure to create a database.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Virtual methods of Database::Internal.
TermList * next()
Advance the current position to the next term in the termlist.
A ChertAllDocsPostList plus pending modifications.
unsigned int max_changesets
The maximum number of changesets which should be kept in the database.
ChertDatabase(const string &db_dir_, int action=Xapian::DB_READONLY_, unsigned int block_size=0u)
Create and open a chert database.
bool locked() const
Return true if the database is open for writing.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Virtual methods of Database::Internal.
void flush_db()
Override methods of ChertTable.
void throw_termlist_table_close_exception() const
void delete_positionlist(Xapian::docid did, const string &tname)
Delete the position list for term tname in document did.
TermList * open_allterms(const string &prefix) const
Virtual methods of Database::Internal.
void replace_document(Xapian::docid did, const Xapian::Document &doc, std::map< Xapian::valueno, ValueStats > &value_stats)
void readahead_for_record(Xapian::docid did) const
friend class ChertAllDocsPostList
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.
void create_and_open(unsigned int blocksize)
Lazy version of ChertTable::create_and_open().
string str(int value)
Convert int to std::string.
Wrapper class around a file descriptor to avoid leaks.
Information about the steps involved in performing a replication.
bool empty() const
Return true if there are no entries in the table.
#define CHERT_MAX_DOCID
The largest docid value supported by chert.
int changeset_count
Number of changesets applied.
void set_block_size(unsigned int block_size_)
Set the block size.
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.
Class for iterating over document values.
#define CONST_STRLEN(S)
Returns the length of a string constant.
void open_tables(chert_revision_number_t revision)
Open tables at specified revision number.
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.
void close()
Close all the tables permanently.
static string make_key(const string &term, Xapian::docid did)
Compose a key from a termname and docid.
Class for iterating over term positions.
void close(bool permanent=false)
Close the Btree.
ChertCursor * cursor_get() const
Get a cursor for reading from the table.
Indicates an attempt to access a database not present.
void write_changed_blocks(int changes_fd)
Append the list of blocks changed to a changeset file.
bool document_exists(Xapian::docid did, Xapian::Internal::intrusive_ptr< const ChertDatabase > db) const
Check if document did exists.
TermList * open_term_list(Xapian::docid did) const
Virtual methods of Database::Internal.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Xapian::Internal::intrusive_ptr< Internal > internal
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
C++ class definition for chert database.
string get_metadata(const string &key) const
Virtual methods of Database::Internal.
A position list in a chert database.
void flush_db()
Override methods of ChertTable.
bool changed
True if and only if the replication corresponds to a change in the live version of the database...
void commit(chert_revision_number_t revision, int changes_fd=-1, const std::string *changes_tail=NULL)
Commit any outstanding changes to the table.
Indicates an attempt to access a document not present in the database.
map< Xapian::valueno, ValueStats > value_stats
A TermList in a chert database.
A ChertPostList plus pending modifications.
Xapian::doccount flush_threshold
If change_count reaches this threshold we automatically flush.
DatabaseCorruptError indicates database corruption was detected.
std::string get_description() const
Return a string describing this object.
void create()
Create the version file.
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 apply()
Apply any outstanding changes to the tables.
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.
Abstract base class for value streams.
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())
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
ChertTermListTable termlist_table
Table storing term lists.
A termlist containing all words which are spelling targets.
void cancel()
Override methods of ChertTable.
Replication protocol version and message numbers.
Xapian::doccount change_count
The number of documents added, deleted, or replaced since the last flush.
Xapian::termcount get_doclength_lower_bound() const
Virtual methods of Database::Internal.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
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.
Xapian::termcount get_doclength(Xapian::docid did) const
Virtual methods of Database::Internal.
Replication support for Xapian databases.
chert_revision_number_t get_latest_revision_number() const
Get the latest revision number stored in this table.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Virtual methods of Database::Internal.
A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree s...
TermList * open_spelling_wordlist() const
Virtual methods of Database::Internal.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
Postlists in chert databases.
Utility functions for replication implementations.
Xapian::docid add_document(const Xapian::Document &document)
Implementation of virtual methods: see Database::Internal for details.
Pack types into strings and unpack them again.
unsigned valueno
The number for a value slot in a document.
Wrappers for low-level POSIX I/O routines.
Various handy helpers which std::string really should provide.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
void dtor_called()
Internal method to perform cleanup when a writable database is destroyed with uncommitted changes...
void delete_document(Xapian::docid did, std::map< Xapian::valueno, ValueStats > &value_stats)
#define MAX_DB_COPIES_PER_CONVERSATION
void send_message(char type, const std::string &s, double end_time)
Send a message.
void write(ChertPostListTable &postlist_table) const
bool term_exists(const string &tname) const
Virtual methods of Database::Internal.
std::string get_value_lower_bound(Xapian::valueno slot) const
void flush_db()
Flush any outstanding changes to the DB file of the table.
map< string, pair< Xapian::termcount_diff, Xapian::termcount_diff > > freq_deltas
Unflushed changes to term frequencies and collection frequencies.
reason lock(bool exclusive, bool wait, std::string &explanation)
Attempt to obtain the lock.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
const int DB_RETRY_LOCK
If the database is already locked, retry the lock.
bool readonly
Whether the database is readonly.
const int DB_CREATE_OR_OVERWRITE
Create database if it doesn't already exist, or overwrite if it does.
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.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
ChertDatabaseStats stats
Database statistics.
Class representing a query.
DatabaseError indicates some sort of database related error.
Chert class for value streams.
void add_word(const std::string &word, Xapian::termcount freqinc)
std::string get_data() const
Get data stored in the document.
void modifications_failed(chert_revision_number_t old_revision, chert_revision_number_t new_revision, const std::string &msg)
Called if a modifications fail.
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...
Abstract base class for iterating term positions in a document.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
void request_document(Xapian::docid) const
Virtual methods of Database::Internal.
Xapian::doccount get_doccount() const
Get the number of records in the table.
A smart pointer that uses intrusive reference counting.
void set_last_docid(Xapian::docid did)
static void throw_database_closed()
Throw an exception indicating that the database is closed.
A termlist containing all terms in a chert database.
chert_doclen_t get_doclength() const
Return the length of this document.
Xapian::termcount get_doclength_lower_bound() const
void add_document(Xapian::termcount doclen)
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 cancel()
Override methods of ChertTable.
TermIterator termlist_begin() const
Start iterating the terms in this document.
void check_wdf(Xapian::termcount wdf)
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
void cancel()
Cancel pending modifications to the database.
A handle representing a document in a Xapian database.
void remove_synonym(const string &word, const string &synonym) const
Virtual methods of Database::Internal.
Wrapper around standard unique_ptr template.
void remove_word(const std::string &word, Xapian::termcount freqdec)
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
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...
LeafPostList * open_post_list(const string &tname) const
Virtual methods of Database::Internal.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Virtual methods of Database::Internal.
TermList * open_metadata_keylist(const std::string &prefix) const
Virtual methods of Database::Internal.
void remove_synonym(const std::string &term, const std::string &synonym)
Remove a synonym for term.
Xapian::totallength get_total_length() const
Virtual methods of Database::Internal.
bool is_modified() const
Override methods of ChertTable.