27 #include <string_view>
39 const Query Query::MatchAll(string_view{});
41 const Query Query::MatchNothing;
59 if (!subquery.
empty())
72 switch (subquery.
internal->get_type()) {
103 std::string_view begin, std::string_view end)
112 }
else if (
usual(begin <= end)) {
118 std::string_view pattern,
123 LOGCALL_CTOR(API,
"Query", op_ | pattern | max_expansion | flags | combiner);
139 if (pattern.empty()) {
140 if (just_flags == 0) {
151 bool match_all =
false;
152 bool question_marks =
false;
153 for (
auto&& ch : pattern) {
156 }
else if (ch ==
'?' && !question_marks &&
158 question_marks =
true;
176 std::string_view pattern,
180 unsigned edit_distance,
181 size_t min_prefix_len)
183 LOGCALL_CTOR(API,
"Query", op_ | pattern | max_expansion | flags | combiner | edit_distance | min_prefix_len);
203 vector<pair<Xapian::termpos, string>> terms;
204 internal->gather_terms(
static_cast<void*
>(&terms));
205 sort(terms.begin(), terms.end());
208 const string * old_term = NULL;
210 for (
auto && i : terms) {
212 if (old_term && old_pos == i.first && *old_term == i.second)
215 v.push_back(i.second);
217 old_term = &(i.second);
228 vector<pair<Xapian::termpos, string>> terms;
229 internal->gather_terms(
static_cast<void*
>(&terms));
230 sort(terms.begin(), terms.end(), [](
231 const pair<Xapian::termpos, string>& a,
232 const pair<Xapian::termpos, string>& b) {
233 return a.second < b.second;
237 const string * old_term = NULL;
238 for (
auto && i : terms) {
240 if (old_term && *old_term == i.second)
243 v.push_back(i.second);
244 old_term = &(i.second);
252 return (
internal ?
internal->get_length() : 0);
260 internal->serialise(result);
267 const char *
p = s.data();
268 const char * end =
p + s.size();
279 return internal->get_type();
285 return internal ?
internal->get_num_subqueries() : 0;
297 return internal->get_wqf();
303 return internal->get_pos();
309 string desc =
"Query(";
311 desc +=
internal->get_description();
322 "OP_PHRASE or OP_ELITE_SET");
408 internal = branch_query->
done();
This class stores a list of terms.
virtual Query::Internal * done()=0
virtual void add_subquery(const Xapian::Query &subquery)=0
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Base class which provides an "external" source of postings.
static Query::Internal * unserialise(const char **p, const char *end, const Registry ®)
Class representing a query.
const Query get_subquery(size_t n) const
Read a top level subquery.
const TermIterator get_terms_begin() const
Begin iterator for terms in the query object.
const TermIterator get_unique_terms_begin() const
Begin iterator for unique terms in the query object.
Xapian::termcount get_leaf_wqf() const
Get the wqf parameter of a leaf node.
std::string get_description() const
Return a string describing this object.
void init(Query::op op_, size_t n_subqueries, Xapian::termcount window=0)
op get_type() const noexcept
Get the type of the top level of the query.
size_t get_num_subqueries() const noexcept
Get the number of subqueries of the top level query.
static const Query unserialise(std::string_view serialised, const Registry ®=Registry())
Unserialise a string and return a Query object.
@ OP_SCALE_WEIGHT
Scale the weight contributed by a subquery.
@ LEAF_POSTING_SOURCE
Value returned by get_type() for a PostingSource.
@ OP_MAX
Pick the maximum weight of any subquery.
@ OP_VALUE_RANGE
Match only documents where a value slot is within a given range.
@ OP_WILDCARD
Wildcard expansion.
@ OP_XOR
Match documents which an odd number of subqueries match.
@ OP_AND_MAYBE
Match the first subquery taking extra weight from other subqueries.
@ LEAF_MATCH_ALL
Value returned by get_type() for MatchAll or equivalent.
@ OP_NEAR
Match only documents where all subqueries match near each other.
@ OP_ELITE_SET
Pick the best N subqueries and combine with OP_OR.
@ OP_AND
Match only documents which all subqueries match.
@ LEAF_MATCH_NOTHING
Value returned by get_type() for MatchNothing or equivalent.
@ OP_OR
Match documents which at least one subquery matches.
@ OP_FILTER
Match like OP_AND but only taking weight from the first subquery.
@ OP_PHRASE
Match only documents where all subqueries match near and in order.
@ OP_VALUE_LE
Match only documents where a value slot is <= a given value.
@ OP_SYNONYM
Match like OP_OR but weighting as if a single term.
@ OP_AND_NOT
Match documents which the first subquery matches but no others do.
@ OP_EDIT_DISTANCE
Edit distance expansion.
@ LEAF_TERM
Value returned by get_type() for a term.
@ OP_VALUE_GE
Match only documents where a value slot is >= a given value.
@ OP_INVALID
Construct an invalid query.
void add_subquery(bool positional, const Xapian::Query &subquery)
std::string serialise() const
Serialise this object into a string.
Xapian::termpos get_leaf_pos() const
Get the pos parameter of a leaf node.
static const Xapian::Query MatchNothing
A query matching no documents.
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.
@ WILDCARD_PATTERN_MULTI
Support * which matches 0 or more characters.
@ WILDCARD_PATTERN_SINGLE
Support ? which matches a single character.
Xapian::Internal::intrusive_ptr< Internal > internal
Query() noexcept
Construct a query matching no documents.
Registry for user subclasses.
Class for iterating over a list of terms.
UnimplementedError indicates an attempt to use an unimplemented feature.
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Hierarchy of classes which Xapian can throw as exceptions.
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_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various assertion macros.
A vector-like container of terms which can be iterated.