Class representing a query. More...
Public Types | |
enum | op { OP_AND = 0, OP_OR = 1, OP_AND_NOT = 2, OP_XOR = 3, OP_AND_MAYBE = 4, OP_FILTER = 5, OP_NEAR = 6, OP_PHRASE = 7, OP_VALUE_RANGE = 8, OP_SCALE_WEIGHT = 9, OP_ELITE_SET = 10, OP_VALUE_GE = 11, OP_VALUE_LE = 12, OP_SYNONYM = 13, OP_MAX = 14, OP_WILDCARD = 15, OP_INVALID = 99, LEAF_TERM = 100, LEAF_POSTING_SOURCE, LEAF_MATCH_ALL, LEAF_MATCH_NOTHING } |
Query operators. More... | |
enum | { WILDCARD_LIMIT_ERROR, WILDCARD_LIMIT_FIRST, WILDCARD_LIMIT_MOST_FREQUENT } |
Public Member Functions | |
Query () | |
Default constructor. | |
~Query () | |
Destructor. | |
Query (const Query &o) | |
Copying is allowed. More... | |
Query & | operator= (const Query &o) |
Copying is allowed. More... | |
Query (const std::string &term, Xapian::termcount wqf=1, Xapian::termpos pos=0) | |
Construct a Query object for a term. More... | |
Query (Xapian::PostingSource *source) | |
Construct a Query object for a PostingSource. More... | |
Query (double factor, const Xapian::Query &subquery) | |
Scale using OP_SCALE_WEIGHT. More... | |
Query (op op_, const Xapian::Query &subquery, double factor) | |
Scale using OP_SCALE_WEIGHT. More... | |
Query (op op_, const Xapian::Query &a, const Xapian::Query &b) | |
Construct a Query object by combining two others. More... | |
Query (op op_, const std::string &a, const std::string &b) | |
Construct a Query object by combining two terms. More... | |
Query (op op_, Xapian::valueno slot, const std::string &limit) | |
Construct a Query object for a single-ended value range. More... | |
Query (op op_, Xapian::valueno slot, const std::string &begin, const std::string &end) | |
Construct a Query object for a value range. More... | |
Query (op op_, const std::string &pattern, Xapian::termcount max_expansion=0, int max_type=WILDCARD_LIMIT_ERROR, op combiner=OP_SYNONYM) | |
Query constructor for OP_WILDCARD queries. More... | |
template<typename I > | |
Query (op op_, I begin, I end, Xapian::termcount window=0) | |
Construct a Query object from a begin/end iterator pair. More... | |
const TermIterator | get_terms_begin () const |
Begin iterator for terms in the query object. | |
const TermIterator | get_terms_end () const |
End iterator for terms in the query object. | |
const TermIterator | get_unique_terms_begin () const |
Begin iterator for unique terms in the query object. More... | |
Xapian::termcount | get_length () const |
Return the length of this query object. More... | |
bool | empty () const |
Check if this query is Xapian::Query::MatchNothing. More... | |
std::string | serialise () const |
Serialise this object into a string. More... | |
op | get_type () const |
Get the type of the top level of the query. More... | |
size_t | get_num_subqueries () const |
Get the number of subqueries of the top level query. More... | |
const Query | get_subquery (size_t n) const |
Read a top level subquery. More... | |
std::string | get_description () const |
Return a string describing this object. | |
const Query | operator &= (const Query &o) |
Combine with another Xapian::Query object using OP_AND. More... | |
const Query | operator|= (const Query &o) |
Combine with another Xapian::Query object using OP_OR. More... | |
const Query | operator^= (const Query &o) |
Combine with another Xapian::Query object using OP_XOR. More... | |
const Query | operator*= (double factor) |
Scale using OP_SCALE_WEIGHT. More... | |
const Query | operator/= (double factor) |
Inverse scale using OP_SCALE_WEIGHT. More... | |
Query (Query::op op_) | |
Construct with just an operator. More... | |
Static Public Member Functions | |
static const Query | unserialise (const std::string &serialised, const Registry ®=Registry()) |
Unserialise a string and return a Query object. More... | |
Static Public Attributes | |
static const Xapian::Query | MatchNothing |
A query matching no documents. More... | |
static const Xapian::Query | MatchAll |
A query matching all documents. More... | |
Class representing a query.
anonymous enum |
Enumerator | |
---|---|
WILDCARD_LIMIT_ERROR | Throw an error if OP_WILDCARD exceeds its expansion limit. Xapian::WildcardError will be thrown when the query is actually run. |
WILDCARD_LIMIT_FIRST | Stop expanding when OP_WILDCARD reaches its expansion limit. This makes the wildcard expand to only the first N terms (sorted by byte order). |
WILDCARD_LIMIT_MOST_FREQUENT | Limit OP_WILDCARD expansion to the most frequent terms. If OP_WILDCARD would expand to more than its expansion limit, the most frequent terms are taken. This approach works well for cases such as expanding a partial term at the end of a query string which the user hasn't finished typing yet - as well as being less expense to evaluate than the full expansion, using only the most frequent terms tends to give better results too. |
enum Xapian::Query::op |
Query operators.
Enumerator | |
---|---|
OP_ELITE_SET | Pick the best N subqueries and combine with OP_OR. If you want to implement a feature which finds documents similar to a piece of text, an obvious approach is to build an "OR" query from all the terms in the text, and run this query against a database containing the documents. However such a query can contain a lots of terms and be quite slow to perform, yet many of these terms don't contribute usefully to the results. The OP_ELITE_SET operator can be used instead of OP_OR in this situation. OP_ELITE_SET selects the most important ''N'' terms and then acts as an OP_OR query with just these, ignoring any other terms. This will usually return results just as good as the full OP_OR query, but much faster. In general, the OP_ELITE_SET operator can be used when you have a large OR query, but it doesn't matter if the search completely ignores some of the less important terms in the query. The subqueries don't have to be terms, but if they aren't then OP_ELITE_SET will look at the estimated frequencies of the subqueries and so could pick a subset which don't actually match any documents even if the full OR would match some. You can specify a parameter to the query constructor which control the number of terms which OP_ELITE_SET will pick. If not specified, this defaults to 10 (Xapian used to default to Xapian::Query query(Xapian::Query::OP_ELITE_SET, subqs.begin(), subqs.end(), 7); If the number of subqueries is less than this threshold, OP_ELITE_SET behaves identically to OP_OR. |
|
inline |
Copying is allowed.
The internals are reference counted, so copying is cheap.
Xapian::Query::Query | ( | const std::string & | term, |
Xapian::termcount | wqf = 1 , |
||
Xapian::termpos | pos = 0 |
||
) |
Construct a Query object for a term.
|
explicit |
Construct a Query object for a PostingSource.
Xapian::Query::Query | ( | double | factor, |
const Xapian::Query & | subquery | ||
) |
Scale using OP_SCALE_WEIGHT.
factor | Non-negative real number to multiply weights by. |
subquery | Query object to scale weights from. |
Xapian::Query::Query | ( | op | op_, |
const Xapian::Query & | subquery, | ||
double | factor | ||
) |
Scale using OP_SCALE_WEIGHT.
In this form, the op_ parameter is totally redundant - use Query(factor, subquery) in preference.
op_ | Must be OP_SCALE_WEIGHT. |
factor | Non-negative real number to multiply weights by. |
subquery | Query object to scale weights from. |
|
inline |
Construct a Query object by combining two others.
op_ | The operator to combine the queries with. |
a | First subquery. |
b | Second subquery. |
|
inline |
Construct a Query object by combining two terms.
op_ | The operator to combine the terms with. |
a | First term. |
b | Second term. |
Xapian::Query::Query | ( | op | op_, |
Xapian::valueno | slot, | ||
const std::string & | limit | ||
) |
Construct a Query object for a single-ended value range.
op_ | Must be OP_VALUE_LE or OP_VALUE_GE currently. |
slot | The value slot to work over. |
limit | The limit of the range. |
Xapian::Query::Query | ( | op | op_, |
Xapian::valueno | slot, | ||
const std::string & | begin, | ||
const std::string & | end | ||
) |
Construct a Query object for a value range.
op_ | Must be OP_VALUE_RANGE currently. |
slot | The value slot to work over. |
begin | Start of the range. |
end | End of the range. |
Xapian::Query::Query | ( | op | op_, |
const std::string & | pattern, | ||
Xapian::termcount | max_expansion = 0 , |
||
int | max_type = WILDCARD_LIMIT_ERROR , |
||
op | combiner = OP_SYNONYM |
||
) |
Query constructor for OP_WILDCARD queries.
op_ | Must be OP_WILDCARD |
pattern | The wildcard pattern - currently this is just a string and the wildcard expands to terms which start with exactly this string. |
max_expansion | The maximum number of terms to expand to (default: 0, which means no limit) |
max_type | How to enforce max_expansion - one of WILDCARD_LIMIT_ERROR (the default), WILDCARD_LIMIT_FIRST or WILDCARD_LIMIT_MOST_FREQUENT. When searching multiple databases, the expansion limit is currently applied independently for each database, so the total number of terms may be higher than the limit. This is arguably a bug, and may change in future versions. |
combiner | The op_ to combine the terms with - one of OP_SYNONYM (the default), OP_OR or OP_MAX. |
|
inline |
Construct a Query object from a begin/end iterator pair.
Dereferencing the iterator should return a Xapian::Query, a non-NULL Xapian::Query*, a std::string or a type which converts to one of these (e.g. const char*).
op_ | The operator to combine the queries with. |
begin | Begin iterator. |
end | End iterator. |
window | Window size for OP_NEAR and OP_PHRASE, or 0 to use the number of subqueries as the window size (default: 0). |
|
inlineexplicit |
Construct with just an operator.
op_ | The operator to use - currently only OP_INVALID is useful. |
|
inline |
Check if this query is Xapian::Query::MatchNothing.
Xapian::termcount Xapian::Query::get_length | ( | ) | const |
Return the length of this query object.
size_t Xapian::Query::get_num_subqueries | ( | ) | const |
Get the number of subqueries of the top level query.
const Query Xapian::Query::get_subquery | ( | size_t | n | ) | const |
Read a top level subquery.
n | Return the n-th subquery (starting from 0) - only valid when 0 <= n < get_num_subqueries(). |
op Xapian::Query::get_type | ( | ) | const |
Get the type of the top level of the query.
const TermIterator Xapian::Query::get_unique_terms_begin | ( | ) | const |
Begin iterator for unique terms in the query object.
Terms are sorted and terms with the same name removed from the list.
Combine with another Xapian::Query object using OP_AND.
|
inline |
Scale using OP_SCALE_WEIGHT.
factor | Non-negative real number to multiply weights by. |
|
inline |
Inverse scale using OP_SCALE_WEIGHT.
factor | Positive real number to divide weights by. |
Copying is allowed.
The internals are reference counted, so assignment is cheap.
Combine with another Xapian::Query object using OP_XOR.
Combine with another Xapian::Query object using OP_OR.
std::string Xapian::Query::serialise | ( | ) | const |
Serialise this object into a string.
|
static |
Unserialise a string and return a Query object.
serialised | the string to unserialise. |
reg | Xapian::Registry object to use to unserialise user-subclasses of Xapian::PostingSource (default: standard registry). |
|
static |
A query matching all documents.
Exactly equivalent to Xapian::Query(std::string()).
Referenced by Xapian::operator/().
|
static |
A query matching no documents.
Exactly equivalent to Xapian::Query().