47 PostingSource::~PostingSource() { }
50 PostingSource::get_weight()
const
58 while (!at_end() && get_docid() < did) {
71 PostingSource::clone()
const
83 PostingSource::serialise()
const
89 PostingSource::unserialise(
const string &)
const
95 PostingSource::unserialise_with_registry(
const std::string &s,
98 return unserialise(s);
110 const char* msg =
"Either PostingSource::reset() or PostingSource::init() "
111 "must be overridden";
116 PostingSource::get_description()
const
118 return "Xapian::PostingSource subclass";
122 ValuePostingSource::get_termfreq_min()
const
128 ValuePostingSource::get_termfreq_est()
const
134 ValuePostingSource::get_termfreq_max()
const
140 ValuePostingSource::next(
double min_wt)
144 value_it = db.valuestream_begin(slot);
149 if (value_it == db.valuestream_end(slot))
return;
151 if (min_wt > get_maxweight()) {
152 value_it = db.valuestream_end(slot);
162 value_it = db.valuestream_begin(slot);
164 if (value_it == db.valuestream_end(slot))
return;
167 if (min_wt > get_maxweight()) {
168 value_it = db.valuestream_end(slot);
171 value_it.skip_to(min_docid);
179 value_it = db.valuestream_begin(slot);
181 if (value_it == db.valuestream_end(slot))
return true;
184 if (min_wt > get_maxweight()) {
185 value_it = db.valuestream_end(slot);
188 return value_it.check(min_docid);
192 ValuePostingSource::at_end()
const
194 return started && value_it == db.valuestream_end(slot);
198 ValuePostingSource::get_docid()
const
200 return value_it.get_docid();
208 set_maxweight(DBL_MAX);
209 termfreq_max = db.get_value_freq(slot);
210 termfreq_est = termfreq_max;
211 termfreq_min = termfreq_max;
215 ValuePostingSource::get_description()
const
217 string desc(
"Xapian::ValuePostingSource(slot=");
218 desc +=
str(get_slot());
246 return string(
"Xapian::ValueWeightPostingSource");
260 const char *
p = s.data();
261 const char * end =
p + s.size();
278 if (upper_bound.empty()) {
290 string desc(
"Xapian::ValueWeightPostingSource(slot=");
300 max_weight_in_map(0.0)
337 unique_ptr<ValueMapPostingSource> res(
339 map<string, double>::const_iterator i;
341 res->add_mapping(i->first, i->second);
344 return res.release();
350 return string(
"Xapian::ValueMapPostingSource");
360 map<string, double>::const_iterator i;
372 const char *
p = s.data();
373 const char * end =
p + s.size();
388 return res.release();
401 string desc(
"Xapian::ValueMapPostingSource(slot=");
516 return string(
"Xapian::FixedWeightPostingSource");
528 const char *
p = s.data();
529 const char * s_end =
p + s.size();
549 string desc(
"Xapian::FixedWeightPostingSource(wt=");
An indexed database of documents.
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
PostingIterator postlist_end(std::string_view) const noexcept
End iterator corresponding to postlist_begin().
A posting source which returns a fixed weight for all documents.
Xapian::doccount get_termfreq_est() const override
An estimate of the number of documents this object can return.
Xapian::PostingIterator it
Iterator over all documents.
std::string get_description() const override
Return a string describing this object.
Xapian::docid get_docid() const override
Return the current docid.
std::string name() const override
Name of the posting source class.
std::string serialise() const override
Serialise object parameters into a string.
FixedWeightPostingSource * unserialise(const std::string &serialised) const override
Create object given string serialisation returned by serialise().
void next(double min_wt) override
Advance the current position to the next matching document.
double get_weight() const override
Return the weight contribution for the current document.
Xapian::doccount get_termfreq_min() const override
A lower bound on the number of documents this object can return.
FixedWeightPostingSource(double wt)
Construct a FixedWeightPostingSource.
bool started
Flag indicating if we've started (true if we have).
bool at_end() const override
Return true if the current position is past the last entry in this list.
void reset(const Database &db_, Xapian::doccount shard_index) override
Set this PostingSource to the start of the list of postings.
Xapian::doccount get_termfreq_max() const override
An upper bound on the number of documents this object can return.
Xapian::docid check_docid
The docid last passed to check() (0 if check() wasn't the last move).
Xapian::doccount termfreq
Number of documents in the posting source.
void skip_to(Xapian::docid min_docid, double min_wt) override
Advance to the specified docid.
bool check(Xapian::docid min_docid, double min_wt) override
Check if the specified docid occurs.
FixedWeightPostingSource * clone() const override
Clone the posting source.
Xapian::Database db
The database we're reading documents from.
InvalidOperationError indicates the API was used in an invalid way.
Indicates a problem communicating with a remote database.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Base class which provides an "external" source of postings.
void set_maxweight(double max_weight)
Specify an upper bound on what get_weight() will return from now on.
double get_maxweight() const noexcept
Return the currently set upper bound on what get_weight() can return.
Registry for user subclasses.
UnimplementedError indicates an attempt to use an unimplemented feature.
A posting source which looks up weights in a map using values as the key.
void add_mapping(const std::string &key, double wt)
Add a mapping.
ValueMapPostingSource * clone() const override
Clone the posting source.
void reset(const Database &db_, Xapian::doccount shard_index) override
Set this PostingSource to the start of the list of postings.
std::map< std::string, double > weight_map
The value -> weight map.
std::string name() const override
Name of the posting source class.
double max_weight_in_map
The maximum weight in weight_map.
void clear_mappings()
Clear all mappings.
std::string serialise() const override
Serialise object parameters into a string.
void set_default_weight(double wt)
Set a default weight for document values not in the map.
std::string get_description() const override
Return a string describing this object.
double get_weight() const override
Return the weight contribution for the current document.
ValueMapPostingSource * unserialise(const std::string &serialised) const override
Create object given string serialisation returned by serialise().
double default_weight
The default weight.
ValueMapPostingSource(Xapian::valueno slot_)
Construct a ValueMapPostingSource.
A posting source which generates weights from a value slot.
bool at_end() const
Return true if the current position is past the last entry in this list.
void reset(const Database &db_, Xapian::doccount shard_index)
Set this PostingSource to the start of the list of postings.
Xapian::Database get_database() const
The database we're reading values from.
bool get_started() const
Flag indicating if we've started (true if we have).
std::string get_value() const
Read current value.
Xapian::valueno get_slot() const
The slot we're reading values from.
A posting source which reads weights from a value slot.
std::string name() const
Name of the posting source class.
void reset(const Database &db_, Xapian::doccount shard_index)
Set this PostingSource to the start of the list of postings.
ValueWeightPostingSource(Xapian::valueno slot_)
Construct a ValueWeightPostingSource.
std::string serialise() const
Serialise object parameters into a string.
double get_weight() const
Return the weight contribution for the current document.
ValueWeightPostingSource * clone() const
Clone the posting source.
std::string get_description() const
Return a string describing this object.
ValueWeightPostingSource * unserialise(const std::string &serialised) const
Create object given string serialisation returned by serialise().
Virtual base class for Database internals.
Class representing a document.
Abstract base class for a document.
Hierarchy of classes which Xapian can throw as exceptions.
string str(int value)
Convert int to std::string.
The Xapian namespace contains public interfaces for the Xapian library.
double sortable_unserialise(std::string_view serialised) noexcept
Convert a string encoded using sortable_serialise back to a floating point number.
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.
Various assertion macros.
void unpack_throw_serialisation_error(const char *p)
Throw appropriate SerialisationError.
Pack types into strings and unpack them again.
bool unpack_uint_last(const char **p, const char *end, U *result)
Decode an unsigned integer as the last item in a string.
bool unpack_string(const char **p, const char *end, std::string &result)
Decode a std::string from a string.
void pack_uint_last(std::string &s, U value)
Append an encoded unsigned integer to a string as the last item.
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.
External sources of posting information.
Class for managing a tree of PostList objects.
parsing a user query string to build a Xapian::Query object
string serialise_double(double v)
Serialise a double to a string.
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
functions to serialise and unserialise a double
Convert types to std::string.