38 #include <string_view>
51 Database::Internal::size_type
52 Database::Internal::size()
const
58 Database::Internal::keep_alive()
69 Database::Internal::get_unique_terms_lower_bound()
const
71 return get_doclength_upper_bound() ? 1 : 0;
75 Database::Internal::get_unique_terms_upper_bound()
const
77 return get_doclength_upper_bound();
83 Database::Internal::dtor_called_()
86 if (transaction_active()) {
87 end_transaction(
false);
101 Database::Internal::commit()
109 Database::Internal::cancel()
117 Database::Internal::begin_transaction(
bool flushed)
119 if (state != TRANSACTION_NONE) {
120 if (transaction_active()) {
124 if (is_read_only()) {
126 "with a read-only shard");
134 state = TRANSACTION_FLUSHED;
136 state = TRANSACTION_UNFLUSHED;
141 Database::Internal::end_transaction(
bool do_commit)
143 if (!transaction_active()) {
144 if (state != TRANSACTION_NONE) {
145 if (is_read_only()) {
147 "WritableDatabase::commit_transaction(): "
148 "called with a read-only shard" :
149 "WritableDatabase::cancel_transaction(): "
150 "called with a read-only shard");
155 "WritableDatabase::commit_transaction(): not in a "
157 "WritableDatabase::cancel_transaction(): not in a "
161 auto old_state = state;
162 state = TRANSACTION_NONE;
165 }
else if (old_state == TRANSACTION_FLUSHED) {
191 Database::Internal::delete_document(string_view unique_term)
195 if (is_read_only()) {
202 unique_ptr<PostList> pl(open_post_list(unique_term));
211 auto old_state = state;
212 if (state != TRANSACTION_UNIMPLEMENTED)
213 state = TRANSACTION_UNFLUSHED;
215 while (pl->next(), !pl->at_end()) {
216 delete_document(pl->get_docid());
235 Database::Internal::replace_document(string_view unique_term,
240 if (is_read_only()) {
247 unique_ptr<PostList> pl(open_post_list(unique_term));
248 if (!pl || (pl->next(), pl->at_end())) {
250 return add_document(document);
257 auto old_state = state;
258 if (state != TRANSACTION_UNIMPLEMENTED)
259 state = TRANSACTION_UNFLUSHED;
261 replace_document(did, document);
262 while (pl->next(), !pl->at_end()) {
263 delete_document(pl->get_docid());
280 Database::Internal::open_spelling_termlist(string_view)
const
289 Database::Internal::open_spelling_wordlist()
const
298 Database::Internal::get_spelling_frequency(string_view)
const
319 Database::Internal::open_synonym_termlist(string_view)
const
328 Database::Internal::open_synonym_keylist(string_view)
const
337 Database::Internal::add_synonym(string_view, string_view)
const
343 Database::Internal::remove_synonym(string_view, string_view)
const
349 Database::Internal::clear_synonyms(string_view)
const
355 Database::Internal::get_metadata(string_view)
const
361 Database::Internal::open_metadata_keylist(string_view)
const
369 Database::Internal::set_metadata(string_view, string_view)
375 Database::Internal::reopen()
389 Database::Internal::write_changesets_to_fd(
int, string_view,
bool,
396 Database::Internal::get_revision()
const
402 Database::Internal::get_uuid()
const
421 Database::Internal::locked()
const
427 Database::Internal::update_lock(
int flags)
429 if (flags == Xapian::DB_READONLY_)
return this;
443 :
p(p_),
term(term_) {
451 const string& get_term()
const {
return term; }
468 vector<unique_ptr<Pos>>& heap,
469 size_t prefix_size = 0)
474 if (!end.empty() &&
term >= end) {
479 (start_pos ? poslist->
skip_to(start_pos) : poslist->
next()) &&
480 (end_pos == LAST_POS || poslist->
get_position() <= end_pos)) {
481 heap.emplace_back(
new Pos(
term.substr(prefix_size), poslist));
485 }
while (termlist->
next() == NULL);
491 std::string_view prefix,
497 end_pos = numeric_limits<decltype(end_pos)>::max();
502 length = numeric_limits<decltype(length)>::max();
506 bool operator()(
const unique_ptr<Pos>& a,
const unique_ptr<Pos>& b) {
507 if (a->get_pos() != b->get_pos()) {
508 return a->get_pos() > b->get_pos();
510 return a->get_term() > b->get_term();
514 vector<unique_ptr<Pos>> heap;
516 unique_ptr<TermList> termlist(open_term_list_direct(did));
517 if (
usual(termlist)) {
518 if (prefix.empty()) {
519 if (termlist->next() == NULL) {
522 if (termlist->skip_to(
"[") == NULL) {
529 if (termlist->skip_to(prefix) == NULL) {
532 string term_ub{prefix};
533 size_t i = term_ub.find_last_not_of(
'\xff');
534 term_ub.resize(i + 1);
535 if (i != string::npos) {
536 term_ub[i] = (
unsigned char)term_ub[i] + 1;
539 term_ub, heap, prefix.size());
549 while (!heap.empty()) {
550 Pos* tip = heap.front().get();
552 if (
pos > end_pos)
break;
557 if (
usual(!result.empty())) {
559 result += (delta == 1 ?
' ' :
'\n');
561 result += tip->get_term();
564 if (result.size() >= length)
break;
572 heap.resize(heap.size() - 1);
static void invalid_operation(const char *msg)
Pos(const string &term_, const Xapian::PositionIterator &p_)
Slow implementation for backends which don't streamed values.
DatabaseLockError indicates failure to lock a database.
Virtual base class for Database internals.
Abstract base class for a document.
Class representing a document.
A smart pointer that uses intrusive reference counting.
InvalidOperationError indicates the API was used in an invalid way.
Abstract base class for iterating term positions in a document.
virtual bool next()=0
Advance to the next entry in the positionlist.
virtual bool skip_to(Xapian::termpos termpos)=0
Skip forward to the specified position.
virtual Xapian::termpos get_position() const =0
Return the current position.
Class representing a query.
Abstract base class for termlists.
virtual PositionList * positionlist_begin() const =0
Return PositionList for the current position.
virtual Internal * next()=0
Advance the current position to the next term in the termlist.
const std::string & get_termname() const
Return the termname at the current position.
UnimplementedError indicates an attempt to use an unimplemented feature.
Abstract base class for value streams.
#define UNSIGNED_OVERFLOW_OK(X)
Virtual base class for Database internals.
Hierarchy of classes which Xapian can throw as exceptions.
C++ STL heap implementation with extensions.
void pop(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
void replace(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
void make(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
The Xapian namespace contains public interfaces for the Xapian library.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
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.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
static void reconstruct_open_poslists(TermList *termlist, Xapian::termpos start_pos, Xapian::termpos end_pos, string_view end, vector< unique_ptr< Pos >> &heap, size_t prefix_size=0)
Various assertion macros.
Abstract base class for postlists.
Slow implementation for backends which don't streamed values.
Various handy string-related helpers.
Information about the steps involved in performing a replication.
Abstract base class for termlists.