42 #include "../flint_lock.h"
66 #include <sys/types.h>
92 #define MAX_SAFE_TERM_LENGTH 245
98 unsigned int block_size)
100 TRANSACTION_READONLY :
103 readonly(flags ==
Xapian::DB_READONLY_),
104 version_file(db_dir),
105 postlist_table(db_dir, readonly),
106 position_table(db_dir, readonly),
110 value_manager(&postlist_table, &termlist_table),
111 synonym_table(db_dir, readonly),
112 spelling_table(db_dir, readonly),
113 docdata_table(db_dir, readonly),
117 LOGCALL_CTOR(DB,
"GlassDatabase", glass_dir | flags | block_size);
128 (block_size & (block_size - 1)) != 0) {
132 int action = flags & Xapian::DB_ACTION_MASK_;
136 if (mkdir(
db_dir.c_str(), 0755) < 0) {
137 int mkdir_errno = errno;
152 db_dir +
"': a database already exists and I was told "
153 "not to overwrite it");
172 postlist_table(fd, version_file.get_offset(), readonly),
173 position_table(fd, version_file.get_offset(), readonly),
174 termlist_table(fd, version_file.get_offset(), readonly,
true),
175 value_manager(&postlist_table, &termlist_table),
176 synonym_table(fd, version_file.get_offset(), readonly),
177 spelling_table(fd, version_file.get_offset(), readonly),
178 docdata_table(fd, version_file.get_offset(), readonly),
193 LOGCALL(DB,
bool,
"GlassDatabase::database_exists", NO_ARGS);
201 LOGCALL_VOID(DB,
"GlassDatabase::create_and_open_tables", flags|block_size);
209 const string& tmpfile = v.
write(
rev, flags);
218 if (!v.
sync(tmpfile,
rev, flags)) {
228 LOGCALL(DB,
bool,
"GlassDatabase::open_tables", flags);
244 if (cur_rev && cur_rev ==
rev) {
294 string message = string(
"Couldn't open changeset ") +
300 const char *start = buf;
306 string message = string(
"Changeset at ") +
307 path +
" does not contain valid magic string";
312 unsigned int changes_version;
315 "changeset at " + path);
322 "changeset at " + path);
326 "changeset at " + path);
332 LOGCALL_VOID(DB,
"GlassDatabase::set_revision_number", flags|new_revision);
335 if (new_revision <=
rev &&
rev != 0) {
336 string m =
"New revision ";
337 m +=
str(new_revision);
338 m +=
" <= old revision ";
367 int saved_errno = errno;
368 (void)unlink(tmpfile.c_str());
386 const string &
term = *t;
395 LOGCALL(DB,
bool,
"GlassDatabase::reopen", NO_ARGS);
416 LOGCALL_VOID(DB,
"GlassDatabase::get_database_write_lock", flags|creating);
425 string msg(
"No glass database found at path '");
438 #ifdef XAPIAN_HAS_REMOTE_BACKEND
447 static const char filenames[] =
457 const char *
p = filenames;
459 size_t len = strlen(
p);
460 filepath.replace(
db_dir.size() + 1, string::npos,
p, len);
480 LOGCALL_VOID(DB,
"GlassDatabase::write_changesets_to_fd", fd |
revision | need_whole_db | info);
481 #ifdef XAPIAN_HAS_REMOTE_BACKEND
488 const char * rev_ptr =
revision.data();
489 const char * rev_end = rev_ptr +
revision.size();
490 if (!
unpack_uint(&rev_ptr, rev_end, &start_rev_num)) {
491 need_whole_db =
true;
507 if (whole_db_copies_left == 0) {
509 "Database changing too fast",
513 whole_db_copies_left--;
523 need_whole_db =
false;
535 if (info != NULL && start_rev_num == needed_rev_num)
549 need_whole_db =
true;
556 need_whole_db =
true;
565 string changes_name =
db_dir +
"/changes" +
str(start_rev_num);
567 if (fd_changes >= 0) {
573 &changeset_start_rev_num,
574 &changeset_end_rev_num);
575 if (changeset_start_rev_num != start_rev_num) {
578 if (changeset_start_rev_num >= changeset_end_rev_num) {
583 start_rev_num = changeset_end_rev_num;
586 if (start_rev_num >= needed_rev_num)
592 need_whole_db =
true;
607 const std::string & msg)
632 "and couldn't open at the old revision: " +
750 while (termlist.
next() == NULL) {
752 if (current_wdf > max_wdf) max_wdf = current_wdf;
762 LOGCALL_VOID(DB,
"GlassDatabase::get_freqs",
term | termfreq_ptr | collfreq_ptr);
777 LOGCALL(DB, std::string,
"GlassDatabase::get_value_lower_bound", slot);
784 LOGCALL(DB, std::string,
"GlassDatabase::get_value_upper_bound", slot);
818 LOGCALL(DB,
bool,
"GlassDatabase::term_exists",
term);
858 if (pl->get_termfreq() == 0) {
907 string_view
term)
const
944 if (!cursor)
return NULL;
965 if (!cursor)
return NULL;
973 LOGCALL(DB,
string,
"GlassDatabase::get_metadata", key);
974 string btree_key(
"\x00\xc0", 2);
984 LOGCALL(DB,
TermList*,
"GlassDatabase::open_metadata_keylist", prefix);
986 if (!cursor)
RETURN(NULL);
1001 LOGCALL(DB,
string,
"GlassDatabase::get_uuid", NO_ARGS);
1046 if (flags == Xapian::DB_READONLY_)
return this;
1049 flags &= ~(DB_ACTION_MASK_ | DB_BACKEND_MASK_);
1057 string desc =
"Glass(";
1059 desc +=
"writable, ";
1073 modify_shortcut_document(NULL),
1074 modify_shortcut_docid(0)
1076 LOGCALL_CTOR(DB,
"GlassWritableDatabase", dir | flags | block_size);
1078 const char *
p = getenv(
"XAPIAN_FLUSH_THRESHOLD");
1082 "be a non-negative integer");
1137 LOGCALL_VOID(DB,
"GlassWritableDatabase::close", NO_ARGS);
1158 throw Xapian::DatabaseError(
"Run out of docids - you'll have to use copydatabase to eliminate any gaps before you can add more documents");
1185 string tname = *
term;
1193 LOGLINE(DB,
"Calculated doclen for new document " << did <<
" as " << new_doclen);
1219 LOGCALL_VOID(DB,
"GlassWritableDatabase::delete_document", did);
1234 doc_really_existed =
true;
1237 if (!doc_really_existed) {
1252 while (termlist.
next() == NULL) {
1281 LOGCALL_VOID(DB,
"GlassWritableDatabase::replace_document", did | document);
1305 bool modifying =
false;
1312 if (!document.
internal->modified()) {
1317 LOGLINE(DB,
"Detected potential document modification shortcut.");
1327 if (!modifying || document.
internal->terms_modified()) {
1328 bool pos_modified = !modifying ||
1329 document.
internal->positions_modified();
1345 string old_tname, new_tname;
1347 bool termlist_at_end = (termlist.
next() != NULL);
1350 if (termlist_at_end) {
1357 cmp = old_tname.compare(new_tname);
1366 new_doclen -= old_wdf;
1370 termlist_at_end = (termlist.
next() != NULL);
1371 }
else if (cmp > 0) {
1374 new_doclen += new_wdf;
1383 }
else if (cmp == 0) {
1393 if (old_wdf != new_wdf) {
1394 new_doclen = new_doclen - old_wdf + new_wdf;
1403 termlist_at_end = (termlist.
next() != NULL);
1406 LOGLINE(DB,
"Calculated doclen for replacement document " << did <<
" as " << new_doclen);
1413 if (new_doclen != old_doclen)
1418 if (!modifying || document.
internal->data_modified()) {
1423 if (!modifying || document.
internal->values_modified()) {
1484 LOGCALL_VOID(DB,
"GlassWritableDatabase::get_freqs",
term | termfreq_ptr | collfreq_ptr);
1500 map<Xapian::valueno, ValueStats>::const_iterator i;
1509 LOGCALL(DB, std::string,
"GlassWritableDatabase::get_value_lower_bound", slot);
1510 map<Xapian::valueno, ValueStats>::const_iterator i;
1519 LOGCALL(DB, std::string,
"GlassWritableDatabase::get_value_upper_bound", slot);
1520 map<Xapian::valueno, ValueStats>::const_iterator i;
1529 LOGCALL(DB,
bool,
"GlassWritableDatabase::term_exists",
term);
1553 bool need_read_pos)
const
1556 (void)need_read_pos;
1577 if (pl->get_termfreq() == 0) {
1598 string_view
term)
const
1611 string_view
term)
const
1625 string_view
term)
const
1630 if (data.empty())
return nullptr;
1639 LOGCALL(DB,
TermList*,
"GlassWritableDatabase::open_allterms", prefix);
1645 if (prefix.empty()) {
1695 string_view synonym)
const
1702 string_view synonym)
const
1716 LOGCALL_VOID(DB,
"GlassWritableDatabase::set_metadata", key | value);
1717 string btree_key(
"\x00\xc0", 2);
1719 if (value.empty()) {
1754 if (flags != Xapian::DB_READONLY_) {
1767 return result.release();
1770 #ifdef DISABLE_GPL_LIBXAPIAN
1771 # error GPL source we cannot relicense included in libxapian
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())
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.
GlassChanges * start(glass_revision_number_t old_rev, glass_revision_number_t rev, int flags)
glass_revision_number_t get_oldest_changeset() const
void set_oldest_changeset(glass_revision_number_t rev)
void commit(glass_revision_number_t new_rev, int flags)
A cursor pointing to a position in a Btree table, for reading several entries in order,...
A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree s...
void get_freqs(std::string_view term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
Find lowest and highest docids actually in use.
string get_metadata(std::string_view key) const
Get the metadata associated with a given key.
TermList * open_term_list(Xapian::docid did) const
friend class GlassPostList
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
bool locked() const
Return true if the database is open for writing.
Xapian::termcount get_wdf_upper_bound(std::string_view term) const
Get an upper bound on the wdf of term term.
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 get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
LeafPostList * open_leaf_post_list(std::string_view term, bool need_read_pos) const
Create a LeafPostList for use during a match.
void apply()
Apply any outstanding changes to the tables.
PostList * open_post_list(std::string_view tname) const
Return a PostList suitable for use in a PostingIterator.
void set_revision_number(int flags, glass_revision_number_t new_revision)
Set the revision number in the tables.
ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
GlassSpellingTable spelling_table
Table storing spelling correction data.
Xapian::Database::Internal * update_lock(int flags)
Lock a read-only database for writing or unlock a writable database.
std::string db_dir
Directory to store databases in.
void cancel()
Cancel any outstanding changes to the tables.
void get_changeset_revisions(const string &path, glass_revision_number_t *startrev, glass_revision_number_t *endrev) const
Get the revision stored in a changeset.
TermList * open_allterms(std::string_view prefix) const
PositionList * open_position_list(Xapian::docid did, std::string_view term) const
TermList * open_metadata_keylist(std::string_view prefix) const
Open a termlist returning each metadata key.
GlassTermListTable termlist_table
Table storing term lists.
Xapian::termcount get_doclength(Xapian::docid did) const
GlassValueManager value_manager
Value manager.
bool term_exists(std::string_view term) const
TermList * open_spelling_termlist(std::string_view word) const
Create a termlist tree from trigrams of word.
Xapian::docid get_lastdocid() const
Return the last used document id of this (sub) database.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Open a handle on a document.
void close()
Close all the tables permanently.
Xapian::doccount get_doccount() const
Virtual methods of Database::Internal.
virtual void read_position_list(GlassRePositionList *pos_list, Xapian::docid did, std::string_view term) const
string get_uuid() const
Get a UUID for the database.
void send_whole_database(RemoteConnection &conn, double end_time)
Send a set of messages which transfer the whole database.
friend class GlassAllTermsList
GlassChanges changes
Replication changesets.
FlintLock lock
Lock object.
GlassVersion version_file
The file describing the Glass database.
void create_and_open_tables(int flags, unsigned int blocksize)
Create new tables, and open them.
void readahead_for_query(const Xapian::Query &query) const
glass_revision_number_t get_next_revision_number() const
Get an object holding the next revision number which should be used in the tables.
friend class GlassSpellingWordsList
Xapian::termcount get_wdfdocmax(Xapian::docid did) const
Get the max wdf in document.
bool readonly
Whether the database is readonly.
void request_document(Xapian::docid) const
Request a document.
virtual Xapian::termcount positionlist_count(Xapian::docid did, std::string_view term) const
TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
Xapian::termcount get_unique_terms_lower_bound() const
Get a lower bound on the unique terms size of a document in this DB.
void modifications_failed(glass_revision_number_t new_revision, const std::string &msg)
Called if a modifications fail.
friend class GlassAllDocsPostList
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
GlassDatabase(std::string_view db_dir_, int flags=Xapian::DB_READONLY_, unsigned int block_size=0u)
Create and open a glass database.
virtual bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
std::string get_description() const
Return a string describing this object.
TermList * open_synonym_keylist(std::string_view prefix) const
Open a termlist returning each term which has synonyms.
GlassPositionListTable position_table
Table storing position lists.
bool reopen()
Re-open tables to recover from an overwritten condition, or just get most up-to-date version.
TermList * open_term_list_direct(Xapian::docid did) const
Like open_term_list() but without MultiTermList wrapper.
GlassDocDataTable docdata_table
Table storing document data.
bool database_exists()
Return true if a database exists at the path specified for this database.
Xapian::doccount get_spelling_frequency(std::string_view word) const
Return the number of times word was added as a spelling.
void write_changesets_to_fd(int fd, std::string_view start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
Write a set of changesets to a file descriptor.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
TermList * open_synonym_termlist(std::string_view term) const
Open a termlist returning synonyms for a term.
GlassPostListTable postlist_table
Table storing posting lists.
friend class GlassWritableDatabase
GlassSynonymTable synonym_table
Table storing synonym data.
bool open_tables(int flags)
Open all tables at most recent revision.
void throw_termlist_table_close_exception() const
friend class GlassTermList
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
friend class GlassSynonymTermList
Xapian::rev get_revision() const
Get the revision number which the tables are opened at.
bool has_positions() const
Check whether this database contains any positional information.
void replace_document_data(Xapian::docid did, const std::string &data)
Replace the document data for document did.
bool delete_document_data(Xapian::docid did)
Delete the document data for document did.
void readahead_for_document(Xapian::docid did) const
A document read from a GlassDatabase.
Xapian::termcount positionlist_count(std::string_view data) const
Return the number of entries in specified position list data.
GlassPositionList * open_position_list(Xapian::docid did, std::string_view term)
A position list in a glass database.
void open(int flags_, const RootInfo &root_info, glass_revision_number_t rev)
bool document_exists(Xapian::docid did, Xapian::Internal::intrusive_ptr< const GlassDatabase > db) const
Check if document did exists.
void get_used_docid_range(Xapian::docid &first, Xapian::docid &last) const
static std::string make_key(std::string_view term, Xapian::docid did)
Compose a key from a termname and docid.
Xapian::termcount get_doclength(Xapian::docid did, Xapian::Internal::intrusive_ptr< const GlassDatabase > db) const
Returns the length of document did.
bool term_exists(std::string_view term) const
void get_freqs(std::string_view term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr, Xapian::termcount *wdfub_ptr=NULL) const
Returns frequencies for a term.
A reusable position list in a glass database.
void assign_data(std::string &&data)
Fill list with data, and move the position to the start.
void read_data(Xapian::docid did, std::string_view term)
Fill list with data, and move the position to the start.
void cancel(const RootInfo &root_info, glass_revision_number_t rev)
Override methods of GlassTable.
Xapian::termcount remove_word(std::string_view word, Xapian::termcount freqdec)
bool is_modified() const
Override methods of GlassTable.
void merge_changes()
Merge in batched-up changes.
TermList * open_termlist(std::string_view word)
Xapian::termcount flush_db()
Returns updated wordfreq upper bound.
void add_word(std::string_view word, Xapian::termcount freqinc)
Xapian::doccount get_word_frequency(std::string_view word) const
void set_wordfreq_upper_bound(Xapian::termcount ub)
void clear_synonyms(std::string_view term)
Remove all synonyms for term.
void flush_db()
Override methods of GlassTable.
void add_synonym(std::string_view term, std::string_view synonym)
Add a synonym for term.
TermList * open_termlist(std::string_view term)
Open synonym termlist for a term.
void remove_synonym(std::string_view term, std::string_view synonym)
Remove a synonym for term.
bool is_modified() const
Override methods of GlassTable.
void cancel(const RootInfo &root_info, glass_revision_number_t rev)
Override methods of GlassTable.
void create_and_open(int flags_, const RootInfo &root_info)
Create a new empty btree structure on disk and open it at the initial revision.
void commit(glass_revision_number_t revision, RootInfo *root_info)
Commit any outstanding changes to the table.
bool exists() const
Determine whether the btree exists on disk.
bool is_open() const
Return true if this table is open.
void flush_db()
Flush any outstanding changes to the DB file of the table.
bool empty() const
Return true if there are no entries in the table.
void open(int flags_, const RootInfo &root_info, glass_revision_number_t rev)
Open the btree.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
void set_changes(GlassChanges *changes)
Set the GlassChanges object to write changed blocks to.
GlassCursor * cursor_get() const
Get a cursor for reading from the table.
bool get_exact_entry(std::string_view key, std::string &tag) const
Read an entry from the table, if and only if it is exactly that being asked for.
void close(bool permanent=false)
Close the Btree.
bool del(std::string_view key)
Delete an entry from the table.
void cancel(const RootInfo &root_info, glass_revision_number_t rev)
Cancel any outstanding changes.
void set_flags(int new_flags)
static void throw_database_closed()
Throw an exception indicating that the database is closed.
void add(std::string_view key, std::string_view tag, bool already_compressed=false)
Add a key/tag pair to the table, replacing any existing pair with the same key.
bool readahead_key(std::string_view key) const
void set_termlist(Xapian::docid did, const Xapian::Document &doc, Xapian::termcount doclen)
Set the termlist data for document did.
void delete_termlist(Xapian::docid did)
Delete the termlist data for document did.
A TermList in a glass database.
Xapian::termcount get_doclength() const
Return the length of this document.
TermList * next()
Advance the current position to the next term in the termlist.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
bool not_present() const
Check if the term isn't present.
Glass class for value streams.
void add_document(Xapian::docid did, const Xapian::Document &doc, std::map< Xapian::valueno, ValueStats > &value_stats)
void set_value_stats(std::map< Xapian::valueno, ValueStats > &value_stats)
Write the updated statistics to the table.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
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
std::string get_value_lower_bound(Xapian::valueno slot) const
void delete_document(Xapian::docid did, std::map< Xapian::valueno, ValueStats > &value_stats)
The GlassVersion class manages the revision files.
RootInfo * root_to_set(Glass::table_type tbl)
void set_oldest_changeset(glass_revision_number_t changeset) const
const RootInfo & get_root(Glass::table_type tbl) const
void check_wdf(Xapian::termcount wdf)
void add_document(Xapian::termcount doclen)
const std::string write(glass_revision_number_t new_rev, int flags)
Xapian::docid get_last_docid() const
glass_revision_number_t get_revision() const
void delete_document(Xapian::termcount doclen)
Xapian::termcount get_doclength_lower_bound() const
std::string get_uuid_string() const
Return UUID in the standard 36 character string format.
void set_spelling_wordfreq_upper_bound(Xapian::termcount ub)
void set_last_docid(Xapian::docid did)
glass_revision_number_t get_oldest_changeset() const
Xapian::termcount get_spelling_wordfreq_upper_bound() const
bool sync(const std::string &tmpfile, glass_revision_number_t new_rev, int flags)
Xapian::doccount get_doccount() const
void set_changes(GlassChanges *changes_)
Xapian::termcount get_wdf_upper_bound() const
Xapian::docid get_next_docid()
void create(unsigned blocksize)
Create the version file.
void read()
Read the version file and check it's a version we understand.
Xapian::totallength get_total_doclen() const
Xapian::termcount get_unique_terms_lower_bound() const
Xapian::termcount get_doclength_upper_bound() const
void flush_postlist_changes()
Flush any unflushed postlist changes, but don't commit them.
Xapian::docid add_document_(Xapian::docid did, const Xapian::Document &document)
bool term_exists(std::string_view term) const
void remove_synonym(std::string_view word, std::string_view synonym) const
Remove a synonym for a term.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
TermList * open_synonym_keylist(std::string_view prefix) const
Open a termlist returning each term which has synonyms.
std::map< Xapian::valueno, ValueStats > value_stats
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
TermList * open_spelling_wordlist() const
Return a termlist which returns the words which are spelling correction targets.
void get_freqs(std::string_view term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void close()
Close all the tables permanently.
bool has_uncommitted_changes() const
Return true if there are uncommitted changes.
ValueList * open_value_list(Xapian::valueno slot) const
Open a value stream.
void commit()
Implementation of virtual methods: see Database::Internal for details.
void replace_document(Xapian::docid did, const Xapian::Document &document)
void delete_document(Xapian::docid did)
void invalidate_doc_object(Xapian::Document::Internal *obj) const
Notify the database that document is no longer valid.
void add_synonym(std::string_view word, std::string_view synonym) const
Add a synonym for a term.
void apply()
Apply changes.
void cancel()
Cancel pending modifications to the database.
LeafPostList * open_leaf_post_list(std::string_view term, bool need_read_pos) const
Create a LeafPostList for use during a match.
void read_position_list(GlassRePositionList *pos_list, Xapian::docid did, std::string_view term) const
PostList * open_post_list(std::string_view term) const
Return a PostList suitable for use in a PostingIterator.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
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...
void add_spelling(std::string_view word, Xapian::termcount freqinc) const
Add a word to the spelling dictionary.
Xapian::Database::Internal * update_lock(int flags)
Lock a read-only database for writing or unlock a writable database.
Xapian::termcount get_doclength(Xapian::docid did) const
Virtual methods of Database::Internal.
void check_flush_threshold()
Check if we should autoflush.
TermList * open_allterms(std::string_view prefix) const
Xapian::doccount flush_threshold
If change_count reaches this threshold we automatically flush.
Xapian::docid add_document(const Xapian::Document &document)
Xapian::docid modify_shortcut_docid
The document ID for the last document returned by open_document().
Xapian::termcount positionlist_count(Xapian::docid did, std::string_view term) const
PositionList * open_position_list(Xapian::docid did, std::string_view term) const
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Open a handle on a document.
bool has_positions() const
Check whether this database contains any positional information.
void set_metadata(std::string_view key, std::string_view value)
Set the metadata associated with a given key.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
Xapian::termcount remove_spelling(std::string_view word, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
Xapian::doccount change_count
The number of documents added, deleted, or replaced since the last flush.
void clear_synonyms(std::string_view word) const
Clear all synonyms for a term.
bool get_deltas(std::string_view term, Xapian::termcount &tf_delta, Xapian::termcount &cf_delta) const
void delete_doclength(Xapian::docid did)
void flush_post_list(GlassPostListTable &table, std::string_view term)
Flush postlist changes for term.
void remove_posting(Xapian::docid did, const std::string &term, Xapian::doccount wdf)
void update_posting(Xapian::docid did, const std::string &term, Xapian::termcount old_wdf, Xapian::termcount new_wdf)
bool get_positionlist(Xapian::docid did, std::string_view term, std::string &s) const
bool has_positions(const GlassPositionListTable &position_table) const
void delete_positionlist(Xapian::docid did, std::string_view term)
void set_positionlist(Xapian::docid did, std::string_view term, std::string_view s)
bool get_doclength(Xapian::docid did, Xapian::termcount &doclen) const
void set_doclength(Xapian::docid did, Xapian::termcount doclen, bool add)
void flush_doclengths(GlassPostListTable &table)
Flush document length changes.
void flush_post_lists(GlassPostListTable &table, std::string_view pfx)
Flush postlist changes for all terms which start with pfx.
void add_posting(Xapian::docid did, const std::string &term, Xapian::doccount wdf)
void flush_pos_lists(GlassPositionListTable &table)
Flush position changes.
void flush(GlassPostListTable &table)
Flush all postlist table changes.
Abstract base class for leaf postlists.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
void send_message(char type, std::string_view 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.
DatabaseCreateError indicates a failure to create a database.
DatabaseError indicates some sort of database related error.
Indicates an attempt to access a database not present.
Virtual base class for Database internals.
void dtor_called()
Helper to process uncommitted changes when a writable db is destroyed.
bool transaction_active() const
Test if a transaction is currently active.
An indexed database of documents.
Abstract base class for a document.
Class representing a document.
std::string get_data() const
Get the document data.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
TermIterator termlist_end() const noexcept
End iterator corresponding to termlist_begin().
TermIterator termlist_begin() const
Start iterating the terms in this document.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
const std::string & get_msg() const noexcept
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.
Abstract base class for postlists.
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 representing a query.
const TermIterator get_unique_terms_begin() const
Begin iterator for unique terms in the query object.
Abstract base class for termlists.
const std::string & get_termname() const
Return the termname at the current position.
Class for iterating over a list of terms.
Abstract base class for value streams.
#define UNSIGNED_OVERFLOW_OK(X)
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.
Utility functions for testing files.
bool dir_exists(const char *path)
Test if a directory exists.
A PostList which iterates over all documents in a GlassDatabase.
A termlist containing all terms in a glass database.
#define MAX_SAFE_TERM_LENGTH
C++ class definition for glass database.
Definitions, types, etc for use inside glass.
#define GLASS_MIN_BLOCKSIZE
Minimum B-tree block size.
#define GLASS_MAX_DOCID
The largest docid value supported by glass.
#define GLASS_DEFAULT_BLOCKSIZE
Default B-tree block size.
uint4 glass_revision_number_t
The revision number of a glass database.
#define GLASS_TABLE_EXTENSION
Glass table extension.
#define GLASS_MAX_BLOCKSIZE
Maximum B-tree block size.
Subclass of GlassTable which holds document data.
A document read from a GlassDatabase.
A position list in a glass database.
Postlists in glass databases.
Internal definitions for glass database replication.
#define CHANGES_MAGIC_STRING
#define REASONABLE_CHANGESET_SIZE
A termlist containing all words which are spelling targets.
A TermList in a glass database.
Glass class for value streams.
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.
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.
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.
const int DB_NO_TERMLIST
When creating a database, don't create a termlist table.
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.
void pack_string(std::string &s, std::string_view value)
Append an encoded std::string to a string.
Parse signed and unsigned type from string and check for trailing characters.
bool parse_unsigned(const char *p, T &res)
Provides wrappers with POSIXy semantics.
RemoteConnection class used by the remote backend.
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 string-related helpers.
#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.