57 Enquire::Enquire(
const Enquire&) =
default;
60 Enquire::operator=(
const Enquire&) =
default;
62 Enquire::Enquire(Enquire&&) =
default;
65 Enquire::operator=(Enquire&&) =
default;
74 internal->query =
query;
75 internal->query_length = query_length;
81 return internal->query;
87 internal->weight.reset(weight.
clone());
93 internal->order = order;
106 internal->sort_functor = NULL;
107 internal->sort_key = sort_key;
108 internal->sort_val_reverse = reverse;
114 if (sorter == NULL) {
118 internal->sort_functor = sorter;
119 internal->sort_val_reverse = reverse;
126 internal->sort_functor = NULL;
127 internal->sort_key = sort_key;
128 internal->sort_val_reverse = reverse;
134 if (sorter == NULL) {
136 "sorter cannot be NULL");
139 internal->sort_functor = sorter;
140 internal->sort_val_reverse = reverse;
147 internal->sort_functor = NULL;
148 internal->sort_key = sort_key;
149 internal->sort_val_reverse = reverse;
155 if (sorter == NULL) {
157 "sorter cannot be NULL");
160 internal->sort_functor = sorter;
161 internal->sort_val_reverse = reverse;
167 internal->collapse_key = collapse_key;
168 internal->collapse_max = collapse_max;
174 internal->percent_threshold = percent_threshold;
175 internal->weight_threshold = weight_threshold;
184 internal->matchspies.push_back(opt_intrusive_ptr<MatchSpy>(spy));
190 internal->matchspies.clear();
196 internal->time_limit = time_limit;
206 return internal->get_mset(first, maxitems, checkatleast, rset, mdecider);
212 return internal->get_matching_terms_begin(did);
217 double expand_k)
const
219 if (eweightname ==
"bo1") {
221 }
else if (eweightname ==
"prob" || eweightname ==
"trad") {
225 "be 'bo1', 'prob' or 'trad'");
227 internal->expand_k = expand_k;
235 double min_weight)
const
237 return internal->get_eset(maxitems, rset, flags, edecider, min_weight);
243 string desc =
"Enquire(db=";
244 desc +=
internal->db.get_description();
247 desc +=
internal->query.get_description();
269 if (percent_threshold && (sort_by ==
VAL || sort_by ==
VAL_REL)) {
271 "sorting primary by value isn't "
272 "currently supported");
280 if (query_length == 0) {
287 first = min(first, docs);
288 maxitems = min(maxitems, docs - first);
289 checkatleast = min(checkatleast, docs);
290 checkatleast = max(checkatleast, first + maxitems);
330 if (first_orig != first) {
331 mset.
internal->set_first(first_orig);
337 mset.
internal->set_stats(stats.release());
349 struct term_and_pos {
357 vector<term_and_pos> query_terms;
360 query_terms.emplace_back(*t,
pos++);
363 if (query_terms.empty())
367 sort(query_terms.begin(), query_terms.end(),
368 [](
const term_and_pos& a,
const term_and_pos& b) {
369 int cmp = a.term.compare(b.term);
370 return cmp ? cmp < 0 : a.pos < b.pos;
377 auto t = db.termlist_begin(did);
379 const string&
term = query_terms[i].term;
380 if (j == 0 ||
term != query_terms[j - 1].
term) {
382 if (t == db.termlist_end(did)) {
389 query_terms[j] = std::move(query_terms[i]);
393 }
while (++i != query_terms.size());
396 query_terms.erase(query_terms.begin() + j, query_terms.end());
399 sort(query_terms.begin(), query_terms.end(),
400 [](
const term_and_pos& a,
const term_and_pos& b) {
401 return a.pos < b.pos;
406 vector<term_and_pos>::const_iterator it;
409 Itor(vector<term_and_pos>::const_iterator it_) : it(it_) {}
420 Itor operator++(
int) {
426 bool operator!=(
const Itor& o) {
return it != o.it; }
430 Itor(query_terms.cend())));
438 double min_weight)
const
441 opt_intrusive_ptr<const ExpandDecider> edecider(edecider_);
445 if (maxitems == 0 || rset.
empty()) {
456 edecider = edft->release();
459 opt_intrusive_ptr<const ExpandDecider> ptr(edft->release());
461 edecider.get()))->release();
468 Bo1EWeight bo1eweight(db, rset.
size(), use_exact_termfreq);
469 eset.
internal->expand(maxitems, db, rset, edecider.get(), bo1eweight,
474 ProbEWeight probeweight(db, rset.
size(), use_exact_termfreq, expand_k);
475 eset.
internal->expand(maxitems, db, rset, edecider.get(), probeweight,
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())
Xapian::MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount check_at_least, Xapian::Weight::Internal &stats, const Xapian::Weight &wtscheme, const Xapian::MatchDecider *mdecider, const Xapian::KeyMaker *sorter, Xapian::valueno collapse_key, Xapian::doccount collapse_max, int percent_threshold, double weight_threshold, Xapian::Enquire::docid_order order, Xapian::valueno sort_key, Xapian::Enquire::Internal::sort_setting sort_by, bool sort_val_reverse, double time_limit, const std::vector< opt_ptr_spy > &matchspies)
Run the match and produce an MSet object.
This class stores a list of terms.
Xapian::Weight subclass implementing the BM25 probabilistic formula.
An indexed database of documents.
Class representing a list of search results.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Internal(const Database &db_)
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast, const RSet *rset, const MatchDecider *mdecider) const
ESet get_eset(termcount maxitems, const RSet &rset, int flags, const ExpandDecider *edecider_, double min_weight) const
TermIterator get_matching_terms_begin(docid did) const
void set_weighting_scheme(const Weight &weight)
Set the weighting scheme to use.
static const int USE_EXACT_TERMFREQ
Flag telling get_eset() to always use the exact term frequency.
void add_matchspy(MatchSpy *spy) XAPIAN_NONNULL()
Add a matchspy.
void set_sort_by_key(KeyMaker *sorter, bool reverse) XAPIAN_NONNULL()
Set the sorting to be by key generated from values only.
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast=0, const RSet *rset=NULL, const MatchDecider *mdecider=NULL) const
Run the query.
void clear_matchspies()
Remove all the matchspies.
TermIterator get_matching_terms_begin(docid did) const
Iterate query terms matching a document.
void set_time_limit(double time_limit)
Set a time limit for the match.
void set_sort_by_value_then_relevance(valueno sort_key, bool reverse)
Set the sorting to be by value, then by relevance for documents with the same value.
void set_cutoff(int percent_threshold, double weight_threshold=0)
Set lower bounds on percentage and/or weight.
void set_expansion_scheme(std::string_view eweightname, double expand_k=1.0) const
Set the weighting scheme to use for expansion.
void set_query(const Query &query, termcount query_length=0)
Set the query.
ESet get_eset(termcount maxitems, const RSet &rset, int flags=0, const ExpandDecider *edecider=NULL, double min_weight=0.0) const
Perform query expansion.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
void set_sort_by_relevance_then_key(KeyMaker *sorter, bool reverse) XAPIAN_NONNULL()
Set the sorting to be by relevance, then by keys generated from values.
void set_sort_by_relevance_then_value(valueno sort_key, bool reverse)
Set the sorting to be by relevance then value.
std::string get_description() const
Return a string describing this object.
void set_sort_by_relevance()
Set the sorting to be by relevance only.
void set_sort_by_value(valueno sort_key, bool reverse)
Set the sorting to be by value only.
const Query & get_query() const
Get the currently set query.
void set_collapse_key(valueno collapse_key, doccount collapse_max=1)
Control collapsing of results.
void set_docid_order(docid_order order)
Set sort order for document IDs.
void set_sort_by_key_then_relevance(KeyMaker *sorter, bool reverse) XAPIAN_NONNULL()
Set the sorting to be by keys generated from values, then by relevance for documents with identical k...
docid_order
Ordering of docids.
static const int INCLUDE_QUERY_TERMS
Flag telling get_eset() to allow query terms in Xapian::ESet.
ExpandDecider subclass which rejects terms using two ExpandDeciders.
ExpandDecider subclass which rejects terms in a specified list.
Virtual base class for expand decider functor.
This class implements the Bo1 scheme for query expansion.
This class implements the probabilistic scheme for query expansion.
A smart pointer that optionally uses intrusive reference counting.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Virtual base class for key making functors.
Class representing a list of search results.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Abstract base class for match deciders.
Abstract base class for match spies.
Class representing a query.
const TermIterator get_terms_begin() const
Begin iterator for terms in the query object.
const TermIterator get_terms_end() const noexcept
End iterator for terms in the query object.
bool empty() const noexcept
Check if this query is Xapian::Query::MatchNothing.
Xapian::termcount get_length() const noexcept
Return the length of this query object.
Class representing a set of documents judged as relevant.
Xapian::doccount size() const
Return number of documents in this RSet object.
bool empty() const
Return true if this RSet object is empty.
Class for iterating over a list of terms.
UnimplementedError indicates an attempt to use an unimplemented feature.
Class to hold statistics for a given collection.
Abstract base class for weighting schemes.
virtual Weight * clone() const =0
Clone this object.
An indexed database of documents.
static void throw_invalid_arg(const char *msg)
Xapian::Enquire internals.
Hierarchy of classes which Xapian can throw as exceptions.
Xapian::ESet::Internal class.
Allow rejection of terms during ESet generation.
Collate statistics and calculate the term weights for the ESet.
Build key strings for MSet ordering or collapsing.
static constexpr auto VAL_REL
static constexpr auto VAL
void sort(_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.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
bool operator!=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
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.
Various assertion macros.
Set of documents judged as relevant.
A vector-like container of terms which can be iterated.
Xapian::Weight::Internal class, holding database and term statistics.