66 LOGCALL(API,
string,
"Document::get_value", slot);
73 LOGCALL(API,
string,
"Document::get_data", NO_ARGS);
81 internal->set_data(data);
103 return internal->get_description();
110 internal->add_value(slot, value);
117 internal->remove_value(slot);
124 internal->clear_values();
132 LOGCALL_VOID(API,
"Document::add_posting", tname | tpos | wdfinc);
136 internal->add_posting(tname, tpos, wdfinc);
142 LOGCALL_VOID(API,
"Document::add_term", tname | wdfinc);
146 internal->add_term(tname, wdfinc);
153 LOGCALL_VOID(API,
"Document::remove_posting", tname | tpos | wdfdec);
157 internal->remove_posting(tname, tpos, wdfdec);
169 if (
rare(termpos_first > termpos_last)) {
172 return internal->remove_postings(term, termpos_first, termpos_last,
180 internal->remove_term(tname);
187 internal->clear_terms();
229 LOGCALL(API, std::string,
"Document::serialise", NO_ARGS);
248 inplace_merge(positions.begin(),
249 positions.begin() + split,
257 LOGCALL(DB,
bool,
"OmDocumentTerm::add_position", wdf_inc | tpos);
259 if (
rare(is_deleted())) {
262 positions.push_back(tpos);
269 if (positions.empty()) {
270 positions.push_back(tpos);
273 if (tpos > positions.back()) {
276 auto i = lower_bound(positions.cbegin(),
277 positions.cbegin() + split,
279 if (i != positions.cbegin() + split && *i == tpos)
282 positions.push_back(tpos);
286 if (tpos == positions.back()) {
299 vector<Xapian::termpos>::iterator i;
300 i = lower_bound(positions.begin(), positions.end(), tpos);
301 if (i == positions.end() || *i != tpos) {
302 auto new_split = positions.size();
304 if (
rare(new_split > numeric_limits<decltype(split)>::max())) {
308 positions.insert(i, tpos);
315 AssertRel(new_split, <=, numeric_limits<decltype(split)>::max());
318 positions.push_back(tpos);
326 LOGCALL_VOID(DB,
"OmDocumentTerm::remove_position", tpos);
330 if (
rare(positions.empty())) {
333 " not in list, can't remove");
337 if (positions.back() == tpos) {
338 positions.pop_back();
339 if (split == positions.size()) {
354 auto i = lower_bound(positions.begin(), positions.end(), tpos);
355 if (i == positions.end() || *i != tpos) {
377 auto i = lower_bound(positions.begin(), positions.end(), termpos_first);
378 if (i == positions.end() || *i > termpos_last) {
381 auto j = upper_bound(i, positions.end(), termpos_last);
382 size_t size_before = positions.size();
383 positions.erase(i, j);
391 description =
"OmDocumentTerm(wdf = ";
392 description +=
str(wdf);
393 description +=
", positions[";
394 description +=
str(positions.size());
403 map<Xapian::valueno, string>::const_iterator i;
404 i = values.find(slot);
405 if (i == values.end())
return string();
408 if (!database.get())
return string();
409 return do_get_value(slot);
415 LOGCALL(DB,
string,
"Xapian::Document::Internal::get_data", NO_ARGS);
416 if (data_here)
RETURN(data);
417 if (!database.get())
RETURN(
string());
431 LOGCALL(DB,
TermList *,
"Document::Internal::open_term_list", NO_ARGS);
435 if (!database.get())
RETURN(NULL);
436 RETURN(database->open_term_list(did));
443 if (!value.empty()) {
444 values[slot] = value;
456 map<Xapian::valueno, string>::iterator i = values.find(slot);
457 if (i == values.end()) {
459 " is not present in document, in " 460 "Xapian::Document::Internal::remove_value()");
477 positions_modified =
true;
479 map<string, OmDocumentTerm>::iterator i;
480 i = terms.find(tname);
481 if (i == terms.end()) {
485 terms.insert(make_pair(tname, std::move(newterm)));
487 if (i->second.add_position(wdfinc, tpos))
497 map<string, OmDocumentTerm>::iterator i;
498 i = terms.find(tname);
499 if (i == terms.end()) {
502 terms.insert(make_pair(tname, std::move(newterm)));
504 if (i->second.increase_wdf(wdfinc))
516 map<string, OmDocumentTerm>::iterator i;
517 i = terms.find(tname);
518 if (i == terms.end() || i->second.is_deleted()) {
522 "' is not present in document, in " 523 "Xapian::Document::Internal::remove_posting()");
525 i->second.remove_position(tpos);
526 if (wdfdec) i->second.decrease_wdf(wdfdec);
527 positions_modified =
true;
538 auto i = terms.find(term);
539 if (i == terms.end() || i->second.is_deleted()) {
543 "' is not present in document, in " 544 "Xapian::Document::Internal::remove_postings()");
546 auto n_removed = i->second.remove_positions(termpos_first, termpos_last);
548 positions_modified =
true;
553 wdf_delta = numeric_limits<Xapian::termcount>::max();
555 i->second.decrease_wdf(wdf_delta);
565 map<string, OmDocumentTerm>::iterator i;
566 i = terms.find(tname);
567 if (i == terms.end() || i->second.is_deleted()) {
571 "' is not present in document, in " 572 "Xapian::Document::Internal::remove_term()");
575 if (!positions_modified) {
576 positions_modified = (i->second.positionlist_count() > 0);
589 positions_modified =
true;
601 return termlist_size;
607 if (terms_here)
return;
608 if (database.get()) {
611 for ( ; t != tend; ++t) {
614 for ( ; p != t.positionlist_end(); ++p) {
617 terms.insert(terms.end(), make_pair(*t, std::move(term)));
620 termlist_size = terms.size();
636 string desc =
"Document(";
646 if (data_here) desc +=
", ";
648 desc +=
str(values.size());
653 if (data_here || values_here) desc +=
", ";
655 desc +=
str(termlist_size);
659 if (database.get()) {
660 if (data_here || values_here || terms_here) desc +=
", ";
675 if (database.get()) {
677 do_get_all_values(values);
686 database->invalidate_doc_object(
this);
The Xapian namespace contains public interfaces for the Xapian library.
#define LOGCALL_STATIC(CATEGORY, TYPE, FUNC, PARAMS)
std::string get_description() const
Return a string describing this object.
void add_value(Xapian::valueno slot, const std::string &value)
Add a new value.
void set_data(const string &)
Xapian::termcount termlist_count() const
The length of the termlist - i.e.
#define AssertRel(A, REL, B)
Xapian::Document unserialise_document(const string &s)
Unserialise a serialised Xapian::Document object.
void add_posting(const string &, Xapian::termpos, Xapian::termcount)
void merge() const
Merge sorted ranges before and after split.
TermList * open_term_list() const
Open a term list.
ValueIterator values_begin() const
Iterator for the values in this document.
Arithmetic operations with overflow checks.
Iteration over values in a document.
A document in the database, possibly plus modifications.
Class for iterating over document values.
void remove_term(const std::string &tname)
Remove a term and all postings associated with it.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Abstract base class for termlists.
Convert types to std::string.
Xapian::termcount termlist_count() const
void clear_terms()
Remove all terms (and postings) from the document.
std::string serialise() const
Serialise document into a string.
void remove_value(Xapian::valueno slot)
Remove any value with the given number.
Xapian::valueno values_count() const
void remove_posting(const string &, Xapian::termpos, Xapian::termcount)
Document()
Make a new empty Document.
docid get_docid() const
Get the document id which is associated with this document (if any).
virtual ~Internal()
Destructor.
TermList which iterates a std::map.
Hierarchy of classes which Xapian can throw as exceptions.
Class for iterating over a list of terms.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
string get_description() const
Return a string describing this object.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
void description_append(std::string &desc, const std::string &s)
void clear_values()
Remove all values associated with the document.
Xapian::termpos remove_postings(const std::string &term, Xapian::termpos term_pos_first, Xapian::termpos term_pos_last, Xapian::termcount wdf_dec=1)
Remove a range of postings for a term.
string get_data() const
Get data stored in document.
string get_value(Xapian::valueno slot) const
Get value by value number.
Iteration over values in a document.
string str(int value)
Convert int to std::string.
Class for iterating over document values.
Xapian::termcount values_count() const
Count the values in this document.
Class for iterating over term positions.
Xapian::Internal::intrusive_ptr< Internal > internal
functions to convert classes to strings and back
Append a string to an object description, escaping invalid UTF-8.
void add_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfinc=1)
Add an occurrence of a term at a particular position.
static Document unserialise(const std::string &serialised)
Unserialise a document from a string produced by serialise().
void remove_term(const string &)
string serialise_document(const Xapian::Document &doc)
Serialise a Xapian::Document object.
void remove_position(Xapian::termpos tpos)
Remove an entry from the position list.
void remove_value(Xapian::valueno)
void add_term(const string &, Xapian::termcount)
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
void append_position(Xapian::termpos termpos)
Append a position.
std::enable_if< std::is_unsigned< T1 >::value &&std::is_unsigned< T2 >::value &&std::is_unsigned< R >::value, bool >::type mul_overflows(T1 a, T2 b, R &res)
Multiplication with overflow checking.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
std::string get_data() const
Get data stored in the document.
API for working with documents.
bool add_position(Xapian::termcount wdf_inc, Xapian::termpos termpos)
Add a position.
void set_data(const std::string &data)
Set data stored in the document.
void add_value(Xapian::valueno, const string &)
std::string get_value(Xapian::valueno slot) const
Get value by number.
Xapian::termpos remove_postings(const string &, Xapian::termpos, Xapian::termpos, Xapian::termcount)
TermIterator termlist_begin() const
Start iterating the terms in this document.
A handle representing a document in a Xapian database.
void remove_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfdec=1)
Remove a posting of a term from the document.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
string get_description() const
Return a string describing this object.
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.
void operator=(const Document &other)
Assignment is allowed.
Xapian::termpos remove_positions(Xapian::termpos termpos_first, Xapian::termpos termpos_last)
Remove a range of positions.