58 vector<InMemoryPosting>::iterator p;
59 p = lower_bound(
docs.begin(),
docs.end(),
68 docs.insert(p, std::move(posting));
69 }
else if (!p->valid) {
74 p->positions.push_back(position);
78 }
else if (use_position) {
80 p->add_position(position);
91 termentry.
tname = tname;
94 vector<InMemoryTermEntry>::iterator p;
95 p = lower_bound(terms.begin(), terms.end(),
103 terms.insert(p, std::move(termentry));
104 }
else if (use_position) {
105 p->add_position(position);
115 const std::string & term_)
117 pos(imterm.
docs.begin()),
118 end(imterm.
docs.end()),
126 auto first_wdf = (*pos).wdf;
174 while (!
at_end() && (*pos).did < did) {
243 :
pos(doc.terms.begin()),
end(doc.terms.
end()), terms(doc.terms.size()),
246 LOGLINE(DB,
"InMemoryTermList::InMemoryTermList(): " <<
247 terms <<
" terms starting from " <<
pos->tname);
318 while (
pos !=
end &&
pos->tname < term) {
369 Assert(did <= db->termlists.size());
412 }
while (did <= db->termlists.size() && !
db->
termlists[
did - 1].is_valid);
423 while (did <= db->termlists.size() && !
db->
termlists[
did - 1].is_valid) {
446 return "InMemoryAllDocsPostList " +
str(
did);
454 : totdocs(0), totlen(0), positions_present(
false), closed(
false)
497 map<string, InMemoryTerm>::const_iterator i =
postlists.find(tname);
498 if (i ==
postlists.end() || i->second.term_freq == 0) {
519 map<string, InMemoryTerm>::const_iterator i =
postlists.find(term);
522 *termfreq_ptr = i->second.term_freq;
524 *collfreq_ptr = i->second.collection_freq;
537 map<Xapian::valueno, ValueStats>::const_iterator i =
valuestats.find(slot);
539 return i->second.freq;
546 map<Xapian::valueno, ValueStats>::const_iterator i =
valuestats.find(slot);
548 return i->second.lower_bound;
555 map<Xapian::valueno, ValueStats>::const_iterator i =
valuestats.find(slot);
557 return i->second.upper_bound;
586 string(
" not found"));
597 string(
" not found"));
613 string(
" not found"));
627 string(
" not found"));
636 map<string, string>::const_iterator i =
metadata.find(key);
653 const std::string & value)
656 if (!value.empty()) {
665 const string & tname)
const 675 auto t = lower_bound(doc.
terms.begin(), doc.
terms.end(),
677 if (t != doc.
terms.end() && t->tname == tname) {
678 return t->positions.size();
685 const string & tname)
const 693 auto t = lower_bound(doc.
terms.begin(), doc.
terms.end(),
695 if (t != doc.
terms.end() && t->tname == tname) {
704 const map<Xapian::valueno, string> &values_)
713 map<Xapian::valueno, string>::const_iterator j;
714 for (j = values_.begin(); j != values_.end(); ++j) {
715 std::pair<map<Xapian::valueno, ValueStats>::iterator,
bool> i;
719 if ((i.first->second.freq)++ == 0) {
722 i.first->second.lower_bound = j->second;
723 i.first->second.upper_bound = j->second;
726 if (j->second < i.first->second.lower_bound) {
727 i.first->second.lower_bound = j->second;
729 if (j->second > i.first->second.upper_bound) {
730 i.first->second.upper_bound = j->second;
754 string(
" not found"));
758 map<Xapian::valueno, string>::const_iterator j;
760 map<Xapian::valueno, ValueStats>::iterator i;
762 if (--(i->second.freq) == 0) {
763 i->second.lower_bound.resize(0);
764 i->second.upper_bound.resize(0);
776 vector<InMemoryTermEntry>::const_iterator i;
777 for (i =
termlists[did - 1].terms.begin();
780 map<string, InMemoryTerm>::iterator t =
postlists.find(i->tname);
782 t->second.collection_freq -= i->wdf;
783 --t->second.term_freq;
790 auto p = lower_bound(t->second.docs.begin(), t->second.docs.end(),
792 if (p != t->second.docs.end() && p->did == did) {
803 LOGCALL_VOID(DB,
"InMemoryDatabase::replace_document", did | document);
808 map<Xapian::valueno, string>::const_iterator j;
810 map<Xapian::valueno, ValueStats>::iterator i;
812 if (--(i->second.freq) == 0) {
813 i->second.lower_bound.resize(0);
814 i->second.upper_bound.resize(0);
830 vector<InMemoryTermEntry>::const_iterator i;
831 for (i =
termlists[did - 1].terms.begin();
834 map<string, InMemoryTerm>::iterator t =
postlists.find(i->tname);
836 t->second.collection_freq -= i->wdf;
837 --t->second.term_freq;
844 auto p = lower_bound(t->second.docs.begin(), t->second.docs.end(),
846 if (p != t->second.docs.end() && p->did == did) {
874 map<Xapian::valueno, string> values;
878 LOGLINE(DB,
"InMemoryDatabase::finish_add_doc(): adding value " <<
889 LOGLINE(DB,
"InMemoryDatabase::finish_add_doc(): adding term " << *i);
935 const string & tname,
947 postlists[tname].add_posting(did, wdf, position, use_position);
948 doc->
add_posting(tname, wdf, position, use_position);
956 map<string, InMemoryTerm>::const_iterator i =
postlists.find(tname);
958 return (i->second.term_freq != 0);
Xapian::Internal::intrusive_ptr< const InMemoryDatabase > db
vector< InMemoryPosting >::const_iterator end
vector< InMemoryTermEntry >::const_iterator end
InMemoryPostList(const InMemoryDatabase *db, const InMemoryTerm &imterm, const std::string &term_)
string get_description() const
Return a string description of this object.
Class to hold statistics for a given slot.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
Abstract base class for postlists.
Xapian::docid make_doc(const string &docdata)
Indicates an attempt to access a closed database.
vector< Xapian::termpos > positions
PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
A database held entirely in memory.
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.
void make_posting(InMemoryDoc *doc, const string &tname, Xapian::docid did, Xapian::termpos position, Xapian::termcount wdf, bool use_position=true)
bool at_end() const
Return true if the current position is past the last entry in this list.
string get_description() const
Return a string description of this object.
Xapian::termcount wdf_upper_bound
void commit()
Implementation of virtual methods: see Database for details.
Iterate all terms in an inmemory db.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
friend class InMemoryAllDocsPostList
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Xapian::doccount get_termfreq() const
Return the exact term frequency.
ValueIterator values_begin() const
Iterator for the values in this document.
Xapian::termcount get_doclength() const
Return the length of current document.
Xapian::totallength totlen
Xapian::termcount get_wdf_upper_bound() const
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
vector< Xapian::termcount > doclengths
void finish_add_doc(Xapian::docid did, const Xapian::Document &document)
A document in the database, possibly plus modifications.
Class for iterating over document values.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Abstract base class for termlists.
A document read from a InMemoryDatabase.
Convert types to std::string.
void cancel()
Implementation of virtual methods: see Database for details.
PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
vector< InMemoryTermEntry >::const_iterator pos
Xapian::docid get_docid() const
Return the current docid.
LeafPostList * open_post_list(const string &tname) const
Open a posting list.
bool has_positions() const
Check whether this database contains any positional information.
TermList * open_allterms(const string &prefix) const
Open an allterms list.
Abstract base class for leaf postlists.
Xapian::doccount get_doccount() const
Return the number of docs in this (sub) database.
TermIterator termlist_end() const
Equivalent end iterator for termlist_begin().
void accumulate_stats(Xapian::Internal::ExpandStats &stats) const
Collate weighting information for the current term.
vector< Xapian::termpos > positions
InMemoryTermList(Xapian::Internal::intrusive_ptr< const InMemoryDatabase > db, Xapian::docid did, const InMemoryDoc &doc, Xapian::termcount len)
Xapian::termcount document_length
void add_posting(const std::string &tname, Xapian::termcount wdf, Xapian::termpos position, bool use_position)
PositionList * open_position_list(Xapian::docid did, const string &tname) const
Open a position list for the given term in the given document.
enum Xapian::Database::Internal::@2 transaction_state
Transaction state.
Hierarchy of classes which Xapian can throw as exceptions.
vector< InMemoryPosting > docs
Class for iterating over a list of terms.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
void add_posting(Xapian::docid did, Xapian::termcount wdf, Xapian::termpos position, bool use_position)
bool at_end() const
Return true if the current position is past the last entry in this list.
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
Class representing a document and the terms indexing it.
void accumulate(size_t shard_index, Xapian::termcount wdf, Xapian::termcount doclen, Xapian::doccount subtf, Xapian::doccount subdbsize)
InMemoryPositionList mypositions
List of positions of the current term.
Xapian::docid add_document(const Xapian::Document &document)
Implementation of virtual methods: see Database for details.
Xapian::docid get_docid() const
Return the current docid.
bool doc_exists(Xapian::docid did) const
Xapian::docid get_lastdocid() const
Return the last used document id of this (sub) database.
Collate statistics and calculate the term weights for the ESet.
vector< InMemoryTermEntry > terms
Xapian::termcount collection_freq
InMemoryDatabase()
Create and open an in-memory database.
string get_termname() const
Return the termname at the current position.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Implementation of virtual methods: see Database for details.
std::map< string, string > metadata
InMemoryAllDocsPostList(const InMemoryDatabase *db)
Internal * next()
Advance the current position to the next document in the postlist.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
A PostList in an inmemory database.
string str(int value)
Convert int to std::string.
A position list in a inmemory database.
TermList * open_term_list(Xapian::docid did) const
Open a term list.
Class for iterating over document values.
C++ class definition for inmemory database access.
std::map< Xapian::valueno, ValueStats > valuestats
Class for iterating over term positions.
Xapian::termcount get_wdf_upper_bound() const
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
void close()
Close the database.
Xapian::Internal::intrusive_ptr< const InMemoryDatabase > db
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
ValueIterator values_end() const
Equivalent end iterator for values_begin().
Indicates an attempt to access a document not present in the database.
vector< std::map< Xapian::valueno, string > > valuelists
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
Xapian::doccount termfreq
void add_values(Xapian::docid did, const map< Xapian::valueno, string > &values_)
static void throw_database_closed()
TermList * skip_to(const std::string &term)
Skip forward to the specified term.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique term in document.
#define AssertEqParanoid(A, B)
class for alltermslists over several databases
vector< std::string > doclists
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Xapian::termcount positionlist_count(Xapian::docid did, const string &tname) const
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
map< string, InMemoryTerm > postlists
void delete_document(Xapian::docid did)
Implementation of virtual methods: see Database for details.
size_t shard_index
Which shard of a multidatabase this is from.
Xapian::Internal::intrusive_ptr< const InMemoryDatabase > db
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
bool term_exists(const string &tname) const
Check whether a given term is in the database.
Collates statistics while calculating term weight in an ESet.
bool reopen()
Reopen the database to the latest available revision.
void make_term(const string &tname)
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 dtor_called()
Internal method to perform cleanup when a writable database is destroyed with uncommitted changes...
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a given document.
vector< InMemoryPosting >::const_iterator pos
TermList * open_metadata_keylist(const std::string &prefix) const
Open a termlist returning each metadata key.
friend class InMemoryDocument
Xapian::termcount get_doclength() const
Return the length of current document.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
std::string get_metadata(const std::string &key) const
Get the metadata associated with a given key.
DatabaseError indicates some sort of database related error.
std::string get_data() const
Get data stored in the document.
Abstract base class for iterating term positions in a document.
void set_metadata(const std::string &key, const std::string &value)
Set the metadata associated with a given key.
Xapian::doccount get_termfreq() const
Return the exact term frequency.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
A smart pointer that uses intrusive reference counting.
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
TermIterator termlist_begin() const
Start iterating the terms in this document.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
A handle representing a document in a Xapian database.
bool at_end() const
Return true if the current position is past the last term in this list.
TermList * next()
Advance the current position to the next term in the termlist.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
void set_data(const OmDocumentTerm::term_positions &positions_)
Fill list with data, and move the position to the start.
Xapian::valueno get_valueno() const
Return the value slot number for the current position.
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
UnimplementedError indicates an attempt to use an unimplemented feature.
Xapian::termcount term_freq
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
vector< InMemoryDoc > termlists