xapian-core  2.0.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Xapian::Query Class Reference

Class representing a query. More...

#include <query.h>

+ Collaboration diagram for Xapian::Query:

Classes

class  Internal
 

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_EDIT_DISTANCE = 16 , OP_INVALID = 99 , LEAF_TERM = 100 , LEAF_POSTING_SOURCE ,
  LEAF_MATCH_ALL , LEAF_MATCH_NOTHING
}
 Query operators. More...
 
enum  {
  WILDCARD_LIMIT_ERROR = 0x00 , WILDCARD_LIMIT_FIRST = 0x01 , WILDCARD_LIMIT_MOST_FREQUENT = 0x02 , WILDCARD_LIMIT_MASK_ = 0x03 ,
  WILDCARD_PATTERN_MULTI = 0x10 , WILDCARD_PATTERN_SINGLE = 0x20 , WILDCARD_PATTERN_GLOB = WILDCARD_PATTERN_MULTI|WILDCARD_PATTERN_SINGLE
}
 

Public Member Functions

 Query () noexcept
 Construct a query matching no documents. More...
 
 ~Query ()
 Destructor. More...
 
 Query (const Query &o)
 Copying is allowed. More...
 
Queryoperator= (const Query &o)
 Copying is allowed. More...
 
 Query (Query &&)=default
 Move constructor. More...
 
Queryoperator= (Query &&)=default
 Move assignment operator. More...
 
 Query (const std::string &term, Xapian::termcount wqf=1, Xapian::termpos pos=0)
 Construct a Query object for a term. More...
 
 Query (const char *term, Xapian::termcount wqf=1, Xapian::termpos pos=0)
 Construct a Query object for a term. More...
 
 Query (std::string_view 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...
 
template<typename S1 , typename S2 , typename std::enable_if< std::is_constructible< std::string_view, S1 >::value &&std::is_constructible< std::string_view, S2 >::value, bool >::type = true>
 Query (op op_, S1 a, S2 b)
 Construct a Query object by combining two terms. More...
 
 Query (op op_, Xapian::valueno slot, std::string_view range_limit)
 Construct a Query object for a single-ended value range. More...
 
 Query (op op_, Xapian::valueno slot, std::string_view range_lower, std::string_view range_upper)
 Construct a Query object for a value range. More...
 
 Query (op op_, std::string_view pattern, Xapian::termcount max_expansion=0, int flags=WILDCARD_LIMIT_ERROR, op combiner=OP_SYNONYM)
 Query constructor for OP_EDIT_DISTANCE and OP_WILDCARD queries. More...
 
 Query (op op_, std::string_view pattern, Xapian::termcount max_expansion, int flags, op combiner, unsigned edit_distance, size_t min_prefix_len=0)
 Query constructor for OP_EDIT_DISTANCE queries. More...
 
template<typename I , typename std::enable_if< std::is_convertible< typename std::iterator_traits< I >::value_type, Xapian::Query >::value||std::is_convertible< typename std::iterator_traits< I >::value_type, Xapian::Query * >::value||std::is_convertible< typename std::iterator_traits< I >::value_type, std::string_view >::value, bool >::type = true, typename iterator_category = typename std::iterator_traits<I>::iterator_category>
 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. More...
 
const TermIterator get_terms_end () const noexcept
 End iterator for terms in the query object. More...
 
const TermIterator get_unique_terms_begin () const
 Begin iterator for unique terms in the query object. More...
 
const TermIterator get_unique_terms_end () const noexcept
 End iterator for unique terms in the query object. More...
 
Xapian::termcount get_length () const noexcept
 Return the length of this query object. More...
 
bool empty () const noexcept
 Check if this query is Xapian::Query::MatchNothing. More...
 
std::string serialise () const
 Serialise this object into a string. More...
 
op get_type () const noexcept
 Get the type of the top level of the query. More...
 
size_t get_num_subqueries () const noexcept
 Get the number of subqueries of the top level query. More...
 
Xapian::termcount get_leaf_wqf () const
 Get the wqf parameter of a leaf node. More...
 
Xapian::termpos get_leaf_pos () const
 Get the pos parameter of a leaf node. 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. More...
 
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 (std::string_view serialised, const Registry &reg=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...
 

Private Member Functions

 Query (Internal *internal_)
 
void init (Query::op op_, size_t n_subqueries, Xapian::termcount window=0)
 
template<typename I >
void init (Query::op op_, Xapian::termcount window, const I &begin, const I &end, std::random_access_iterator_tag)
 
template<typename I >
void init (Query::op op_, Xapian::termcount window, const I &, const I &, std::input_iterator_tag)
 
void add_subquery (bool positional, const Xapian::Query &subquery)
 
void add_subquery (bool, const std::string &subquery)
 
void add_subquery (bool, const char *subquery)
 
void add_subquery (bool, std::string_view subquery)
 
void add_subquery (bool positional, const Xapian::Query *subquery)
 
void done ()
 

Private Attributes

Xapian::Internal::intrusive_ptr< Internalinternal
 

Detailed Description

Class representing a query.

Definition at line 45 of file query.h.

Member Enumeration Documentation

◆ anonymous enum

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.
WILDCARD_LIMIT_MASK_ 
WILDCARD_PATTERN_MULTI 

Support * which matches 0 or more characters.

    @since Added in Xapian 2.0.0
WILDCARD_PATTERN_SINGLE 

Support ? which matches a single character.

    @since Added in Xapian 2.0.0.
WILDCARD_PATTERN_GLOB 

Enable all supported glob-like features.

    @since Added in Xapian 2.0.0.

Definition at line 299 of file query.h.

◆ op

Query operators.

Enumerator
OP_AND 

Match only documents which all subqueries match.

    When used in a weighted context, the weight is the sum of the
    weights for all the subqueries.
OP_OR 

Match documents which at least one subquery matches.

    When used in a weighted context, the weight is the sum of the
    weights for matching subqueries (so additional matching subqueries
    will mean a higher weight).
OP_AND_NOT 

Match documents which the first subquery matches but no others do.

    When used in a weighted context, the weight is just the weight of
    the first subquery.
OP_XOR 

Match documents which an odd number of subqueries match.

    When used in a weighted context, the weight is the sum of the
    weights for matching subqueries (so additional matching subqueries
    will mean a higher weight).
OP_AND_MAYBE 

Match the first subquery taking extra weight from other subqueries.

    When used in a weighted context, the weight is the sum of the
    weights for matching subqueries (so additional matching subqueries
    will mean a higher weight).

    Because only the first subquery determines which documents are
    matched, in a non-weighted context only the first subquery matters.
OP_FILTER 

Match like OP_AND but only taking weight from the first subquery.

    When used in a non-weighted context, OP_FILTER and OP_AND are
    equivalent.

    In older 1.4.x, the third and subsequent subqueries were ignored
    in some situations.  This was fixed in 1.4.15.
OP_NEAR 

Match only documents where all subqueries match near each other.

    The subqueries must match at term positions within the specified
    window size, in any order.

    Currently subqueries must be terms or terms composed with OP_OR.

    When used in a weighted context, the weight is the sum of the
    weights for all the subqueries.
OP_PHRASE 

Match only documents where all subqueries match near and in order.

    The subqueries must match at term positions within the specified
    window size, in the same term position order as subquery order.

    Currently subqueries must be terms or terms composed with OP_OR.

    When used in a weighted context, the weight is the sum of the
    weights for all the subqueries.
OP_VALUE_RANGE 

Match only documents where a value slot is within a given range.

    This operator never contributes weight.
OP_SCALE_WEIGHT 

Scale the weight contributed by a subquery.

    The weight is the weight of the subquery multiplied by the
    specified non-negative scale factor (so if the scale factor is
    zero then the subquery contributes no weight).
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.  If they aren't then
    OP_ELITE_SET could potentially pick a subset which doesn't
    actually match any documents even if the full OR would match some
    (because OP_ELITE_SET currently selects those subqueries which can
    return the highest weights).  This is probably rare in practice
    though.

    You can specify a parameter to the query constructor which controls
    the number of subqueries which OP_ELITE_SET will pick.  If not
    specified, this defaults to 10 (Xapian used to default to
    <code>ceil(sqrt(number_of_subqueries))</code> if there are more
    than 100 subqueries, but this rather arbitrary special case was
    dropped in 1.3.0).  For example, this will pick the best 7 terms:

    <pre>
    Xapian::Query query(Xapian::Query::OP_ELITE_SET, subqs.begin(), subqs.end(), 7);
    </pre>

    If the number of subqueries is less than this threshold,
    OP_ELITE_SET behaves identically to OP_OR.

    When used with a sharded database, OP_ELITE_SET currently picks
    the subqueries to use separately for each shard based on the
    maximum weight they can return in that shard.  This means it
    probably won't select exactly the same terms, and so the results
    of the search may not be exactly the same as for a single database
    with equivalent contents.
OP_VALUE_GE 

Match only documents where a value slot is >= a given value.

    Similar to @a OP_VALUE_RANGE, but open-ended.

    This operator never contributes weight.
OP_VALUE_LE 

Match only documents where a value slot is <= a given value.

    Similar to @a OP_VALUE_RANGE, but open-ended.

    This operator never contributes weight.
OP_SYNONYM 

Match like OP_OR but weighting as if a single term.

    The weight is calculated combining the statistics for the
    subqueries to approximate the weight of a single term occurring
    with those statistics.
OP_MAX 

Pick the maximum weight of any subquery.

    Matches the same documents as @a OP_OR, but the weight contributed
    is the maximum weight from any matching subquery (for OP_OR, it's
    the sum of the weights from the matching subqueries).

    @since Added in Xapian 1.3.2.
OP_WILDCARD 

Wildcard expansion.

    @since Added in Xapian 1.3.3.
OP_EDIT_DISTANCE 

Edit distance expansion.

    Expand to terms within a specified edit distance of a target.

    This works in a fairly similar way to OP_WILDCARD - the difference
    is that instead of expanding to terms matching a wildcard pattern,
    it expands to terms within a specified number of edits (insertion,
    deletion or substitution of a character, or transposition of two
    adjacent characters) of a specified target.

    @since Added in Xapian 2.0.0.
OP_INVALID 

Construct an invalid query.

    This can be useful as a placeholder - for example @a RangeProcessor
    uses it as a return value to indicate that a range hasn't been
    recognised.
LEAF_TERM 

Value returned by get_type() for a term.

LEAF_POSTING_SOURCE 

Value returned by get_type() for a PostingSource.

LEAF_MATCH_ALL 

Value returned by get_type() for MatchAll or equivalent.

    This is returned for any
    <code>Xapian::Query(std::string_view())</code> object.
LEAF_MATCH_NOTHING 

Value returned by get_type() for MatchNothing or equivalent.

    This is returned for any <code>Xapian::Query()</code> object.

Definition at line 78 of file query.h.

Constructor & Destructor Documentation

◆ Query() [1/18]

Xapian::Query::Query ( )
inlinenoexcept

Construct a query matching no documents.

MatchNothing is a static instance of this.

When combined with other Query objects using the various supported operators, Query() works like false in boolean logic, so Query() & q is Query(), while Query() | q is q.

Definition at line 354 of file query.h.

Referenced by operator&=(), operator^=(), operator|=(), and unserialise().

◆ ~Query()

Xapian::Query::~Query ( )
inline

Destructor.

Definition at line 357 of file query.h.

Referenced by Query().

◆ Query() [2/18]

Xapian::Query::Query ( const Query o)
inline

Copying is allowed.

The internals are reference counted, so copying is cheap.

Definition at line 363 of file query.h.

◆ Query() [3/18]

Xapian::Query::Query ( Query &&  )
default

Move constructor.

◆ Query() [4/18]

Xapian::Query::Query ( const std::string &  term,
Xapian::termcount  wqf = 1,
Xapian::termpos  pos = 0 
)
inline

Construct a Query object for a term.

Parameters
termThe term. An empty string constructs a query matching all documents (MatchAll is a static instance of this).
wqfThe within-query frequency. (default: 1)
posThe query position. Currently this is mainly used to determine the order of terms obtained via get_terms_begin(). (default: 0)

Definition at line 386 of file query.h.

◆ Query() [5/18]

Xapian::Query::Query ( const char *  term,
Xapian::termcount  wqf = 1,
Xapian::termpos  pos = 0 
)
inline

Construct a Query object for a term.

Parameters
termThe term. An empty string constructs a query matching all documents (MatchAll is a static instance of this).
wqfThe within-query frequency. (default: 1)
posThe query position. Currently this is mainly used to determine the order of terms obtained via get_terms_begin(). (default: 0)

Definition at line 401 of file query.h.

◆ Query() [6/18]

Xapian::Query::Query ( std::string_view  term,
Xapian::termcount  wqf = 1,
Xapian::termpos  pos = 0 
)

Construct a Query object for a term.

Parameters
termThe term. An empty string constructs a query matching all documents (MatchAll is a static instance of this).
wqfThe within-query frequency. (default: 1)
posThe query position. Currently this is mainly used to determine the order of terms obtained via get_terms_begin(). (default: 0)

Definition at line 43 of file query.cc.

References LOGCALL_CTOR, pos, and term.

◆ Query() [7/18]

Xapian::Query::Query ( Xapian::PostingSource source)
explicit

Construct a Query object for a PostingSource.

Definition at line 49 of file query.cc.

References LOGCALL_CTOR.

◆ Query() [8/18]

Xapian::Query::Query ( double  factor,
const Xapian::Query subquery 
)

Scale using OP_SCALE_WEIGHT.

Parameters
factorNon-negative real number to multiply weights by.
subqueryQuery object to scale weights from.

Definition at line 55 of file query.cc.

References empty(), and LOGCALL_CTOR.

◆ Query() [9/18]

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.

Parameters
op_Must be OP_SCALE_WEIGHT.
factorNon-negative real number to multiply weights by.
subqueryQuery object to scale weights from.

Definition at line 63 of file query.cc.

References internal, LOGCALL_CTOR, OP_SCALE_WEIGHT, OP_VALUE_GE, OP_VALUE_LE, OP_VALUE_RANGE, and rare.

◆ Query() [10/18]

Xapian::Query::Query ( op  op_,
const Xapian::Query a,
const Xapian::Query b 
)
inline

Construct a Query object by combining two others.

Parameters
op_The operator to combine the queries with.
aFirst subquery.
bSecond subquery.

Definition at line 447 of file query.h.

◆ Query() [11/18]

template<typename S1 , typename S2 , typename std::enable_if< std::is_constructible< std::string_view, S1 >::value &&std::is_constructible< std::string_view, S2 >::value, bool >::type = true>
Xapian::Query::Query ( op  op_,
S1  a,
S2  b 
)
inline

Construct a Query object by combining two terms.

Parameters
op_The operator to combine the terms with.
aFirst term.
bSecond term.

Definition at line 467 of file query.h.

◆ Query() [12/18]

Xapian::Query::Query ( op  op_,
Xapian::valueno  slot,
std::string_view  range_limit 
)

Construct a Query object for a single-ended value range.

Parameters
op_Must be OP_VALUE_LE or OP_VALUE_GE currently.
slotThe value slot to work over.
range_limitThe limit of the range.

Definition at line 86 of file query.cc.

References LOGCALL_CTOR, OP_VALUE_GE, OP_VALUE_LE, and usual.

◆ Query() [13/18]

Xapian::Query::Query ( op  op_,
Xapian::valueno  slot,
std::string_view  range_lower,
std::string_view  range_upper 
)

Construct a Query object for a value range.

Parameters
op_Must be OP_VALUE_RANGE currently.
slotThe value slot to work over.
range_lowerLower end of the range.
range_upperUpper end of the range.

Definition at line 102 of file query.cc.

References LOGCALL_CTOR, OP_VALUE_RANGE, rare, and usual.

◆ Query() [14/18]

Xapian::Query::Query ( op  op_,
std::string_view  pattern,
Xapian::termcount  max_expansion = 0,
int  flags = WILDCARD_LIMIT_ERROR,
op  combiner = OP_SYNONYM 
)

Query constructor for OP_EDIT_DISTANCE and OP_WILDCARD queries.

Parameters
op_Must be OP_EDIT_DISTANCE or OP_WILDCARD
patternThe wildcard pattern (for OP_WILDCARD) or target string (for OP_EDIT_DISTANCE). See flags which affects how this pattern is interpreted.
max_expansionThe maximum number of terms to expand to (default: 0, which means no limit)
flagsFlags controlling aspects of the wildcarding - this consists of a bitwise OR of:
  • At most one of WILDCARD_LIMIT_ERROR (the default), WILDCARD_LIMIT_FIRST or WILDCARD_LIMIT_MOST_FREQUENT specifying how to enforce max_expansion.

    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.

  • For OP_WILDCARD: Zero or more of WILDCARD_PATTERN_MULTI and WILDCARD_PATTERN_SINGLE, which specify whether '*' (matching zero or more characters) and '?' (matching exactly one character) are supported. If neither is specified, then a Xapian-1.4-compatible mode is used where the pattern matches terms which start with the pattern interpreted as a literal string.
Parameters
combinerThe Query::op to combine the terms with - one of OP_SYNONYM (the default), OP_OR or OP_MAX.

For OP_WILDCARD: A leading wildcard won't match terms starting with an ASCII capital letter, as this is assumed to be part of a term prefix.

Definition at line 117 of file query.cc.

References LOGCALL_CTOR, OP_EDIT_DISTANCE, OP_MAX, OP_OR, OP_SYNONYM, OP_WILDCARD, rare, WILDCARD_LIMIT_MASK_, WILDCARD_PATTERN_MULTI, WILDCARD_PATTERN_SINGLE, and ~Query().

◆ Query() [15/18]

Xapian::Query::Query ( op  op_,
std::string_view  pattern,
Xapian::termcount  max_expansion,
int  flags,
op  combiner,
unsigned  edit_distance,
size_t  min_prefix_len = 0 
)

Query constructor for OP_EDIT_DISTANCE queries.

This form supports some additional parameters.

Parameters
op_Must be OP_EDIT_DISTANCE.
patternThe target string.
max_expansionThe maximum number of terms to expand to (default: 0, which means no limit)
flagsFlags controlling aspects of the wildcarding:
            * At most one of @a WILDCARD_LIMIT_ERROR (the default),
              @a WILDCARD_LIMIT_FIRST or
              @a WILDCARD_LIMIT_MOST_FREQUENT specifying how to
              enforce max_expansion.

              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.
combinerThe Query::op to combine the terms with - one of OP_SYNONYM (the default), OP_OR or OP_MAX.
edit_distanceThe maximum number of edits allowed between a term and target (an edit is insertion, deletion or substitution of a character, or transposition of two adjacent characters). Default: 2
min_prefix_lenThe length in bytes of any initial substring of target that is required to match exactly. Default: 0
Since
Added in Xapian 2.0.0.

Definition at line 175 of file query.cc.

References LOGCALL_CTOR, OP_EDIT_DISTANCE, OP_MAX, OP_OR, OP_SYNONYM, and rare.

◆ Query() [16/18]

template<typename I , typename std::enable_if< std::is_convertible< typename std::iterator_traits< I >::value_type, Xapian::Query >::value||std::is_convertible< typename std::iterator_traits< I >::value_type, Xapian::Query * >::value||std::is_convertible< typename std::iterator_traits< I >::value_type, std::string_view >::value, bool >::type = true, typename iterator_category = typename std::iterator_traits<I>::iterator_category>
Xapian::Query::Query ( op  op_,
begin,
end,
Xapian::termcount  window = 0 
)
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_view or a type which converts to one of these (e.g. std::string or const char*).

If begin == end then there are no subqueries and the resulting Query won't match anything.

Parameters
op_The operator to combine the queries with.
beginBegin iterator.
endEnd iterator.
windowWindow size for OP_NEAR and OP_PHRASE, or 0 to use the number of subqueries as the window size (default: 0).

Definition at line 605 of file query.h.

◆ Query() [17/18]

Xapian::Query::Query ( Internal internal_)
inlineexplicitprivate

Wrap an existing Internal.

Definition at line 750 of file query.h.

◆ Query() [18/18]

Xapian::Query::Query ( Query::op  op_)
inlineexplicit

Construct with just an operator.

Parameters
op_The operator to use - currently only OP_INVALID is useful.

Definition at line 756 of file query.h.

References OP_INVALID.

Member Function Documentation

◆ add_subquery() [1/5]

void Xapian::Query::add_subquery ( bool  positional,
const Xapian::Query subquery 
)
private

◆ add_subquery() [2/5]

void Xapian::Query::add_subquery ( bool  positional,
const Xapian::Query subquery 
)
inlineprivate

Definition at line 792 of file query.h.

◆ add_subquery() [3/5]

void Xapian::Query::add_subquery ( bool  ,
const char *  subquery 
)
inlineprivate

Definition at line 784 of file query.h.

◆ add_subquery() [4/5]

void Xapian::Query::add_subquery ( bool  ,
const std::string &  subquery 
)
inlineprivate

Definition at line 780 of file query.h.

◆ add_subquery() [5/5]

void Xapian::Query::add_subquery ( bool  ,
std::string_view  subquery 
)
inlineprivate

Definition at line 788 of file query.h.

◆ done()

void Xapian::Query::done ( )
private

Definition at line 403 of file query.cc.

References Xapian::Internal::QueryBranch::done().

◆ empty()

bool Xapian::Query::empty ( ) const
inlinenoexcept

◆ get_description()

string Xapian::Query::get_description ( ) const

Return a string describing this object.

Definition at line 307 of file query.cc.

Referenced by DEFINE_TESTCASE(), main(), and PerfTestLogger::search_end().

◆ get_leaf_pos()

Xapian::termpos Xapian::Query::get_leaf_pos ( ) const

Get the pos parameter of a leaf node.

Since
Added in Xapian 2.0.0.

Definition at line 301 of file query.cc.

Referenced by DEFINE_TESTCASE().

◆ get_leaf_wqf()

Xapian::termcount Xapian::Query::get_leaf_wqf ( ) const

Get the wqf parameter of a leaf node.

Since
Added in Xapian 2.0.0.

Definition at line 295 of file query.cc.

Referenced by DEFINE_TESTCASE().

◆ get_length()

Xapian::termcount Xapian::Query::get_length ( ) const
noexcept

Return the length of this query object.

Definition at line 250 of file query.cc.

References internal.

Referenced by DEFINE_TESTCASE(), and Xapian::Enquire::Internal::get_mset().

◆ get_num_subqueries()

size_t Xapian::Query::get_num_subqueries ( ) const
noexcept

Get the number of subqueries of the top level query.

Definition at line 283 of file query.cc.

Referenced by Xapian::check_query(), and DEFINE_TESTCASE().

◆ get_subquery()

const Query Xapian::Query::get_subquery ( size_t  n) const

Read a top level subquery.

Parameters
nReturn the n-th subquery (starting from 0) - only valid when 0 <= n < get_num_subqueries().

Definition at line 289 of file query.cc.

References get_subquery().

Referenced by Xapian::Internal::QueryAndNot::add_subquery(), Xapian::check_query(), DEFINE_TESTCASE(), and get_subquery().

◆ get_terms_begin()

const TermIterator Xapian::Query::get_terms_begin ( ) const

Begin iterator for terms in the query object.

The iterator returns terms in ascending query position order, and will return the same term in each unique position it occurs in. If you want the terms in sorted order and without duplicates, see get_unique_terms_begin().

Definition at line 198 of file query.cc.

References Heap::sort().

Referenced by DEFINE_TESTCASE(), Xapian::Enquire::Internal::get_eset(), Xapian::Enquire::Internal::get_matching_terms_begin(), and main().

◆ get_terms_end()

const TermIterator Xapian::Query::get_terms_end ( ) const
inlinenoexcept

End iterator for terms in the query object.

Definition at line 639 of file query.h.

Referenced by DEFINE_TESTCASE(), Xapian::Enquire::Internal::get_eset(), Xapian::Enquire::Internal::get_matching_terms_begin(), and main().

◆ get_type()

Xapian::Query::op Xapian::Query::get_type ( ) const
noexcept

Get the type of the top level of the query.

Definition at line 275 of file query.cc.

References LEAF_MATCH_NOTHING.

Referenced by add_subquery(), Xapian::Internal::QueryAndNot::add_subquery(), Terms::as_opwindow_query(), Xapian::check_query(), DEFINE_TESTCASE(), and State::range().

◆ get_unique_terms_begin()

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.

If you want the terms in ascending query position order, see get_terms_begin().

Definition at line 223 of file query.cc.

References Heap::sort().

Referenced by Xapian::Weight::Internal::accumulate_stats(), DEFINE_TESTCASE(), and GlassDatabase::readahead_for_query().

◆ get_unique_terms_end()

const TermIterator Xapian::Query::get_unique_terms_end ( ) const
inlinenoexcept

End iterator for unique terms in the query object.

Definition at line 653 of file query.h.

Referenced by DEFINE_TESTCASE().

◆ init() [1/3]

void Xapian::Query::init ( Query::op  op_,
size_t  n_subqueries,
Xapian::termcount  window = 0 
)
private

◆ init() [2/3]

template<typename I >
void Xapian::Query::init ( Query::op  op_,
Xapian::termcount  window,
const I &  ,
const I &  ,
std::input_iterator_tag   
)
inlineprivate

Definition at line 772 of file query.h.

◆ init() [3/3]

template<typename I >
void Xapian::Query::init ( Query::op  op_,
Xapian::termcount  window,
const I &  begin,
const I &  end,
std::random_access_iterator_tag   
)
inlineprivate

Definition at line 765 of file query.h.

◆ operator&=()

const Query Xapian::Query::operator&= ( const Query o)
inline

Combine with another Xapian::Query object using OP_AND.

Since
Since Xapian 1.4.10, when called on a Query object which is OP_AND and has a reference count of 1, then o is appended as a new subquery (provided o is a different Query object and !o.empty()).

Definition at line 987 of file query.h.

References add_subquery(), Xapian::Query::Internal::get_type(), internal, OP_AND, and Query().

◆ operator*=()

const Query Xapian::Query::operator*= ( double  factor)
inline

Scale using OP_SCALE_WEIGHT.

Parameters
factorNon-negative real number to multiply weights by.

Definition at line 737 of file query.h.

◆ operator/=()

const Query Xapian::Query::operator/= ( double  factor)
inline

Inverse scale using OP_SCALE_WEIGHT.

Parameters
factorPositive real number to divide weights by.

Definition at line 745 of file query.h.

◆ operator=() [1/2]

Query& Xapian::Query::operator= ( const Query o)
inline

Copying is allowed.

The internals are reference counted, so assignment is cheap.

Definition at line 369 of file query.h.

References internal.

◆ operator=() [2/2]

Query& Xapian::Query::operator= ( Query &&  )
default

Move assignment operator.

◆ operator^=()

const Query Xapian::Query::operator^= ( const Query o)
inline

Combine with another Xapian::Query object using OP_XOR.

Since
Since Xapian 1.4.10, when called on a Query object which is OP_XOR and has a reference count of 1, then o is appended as a new subquery (provided o is a different Query object and !o.empty()).

Definition at line 1022 of file query.h.

References add_subquery(), empty(), Xapian::Query::Internal::get_type(), internal, OP_XOR, and Query().

◆ operator|=()

const Query Xapian::Query::operator|= ( const Query o)
inline

Combine with another Xapian::Query object using OP_OR.

Since
Since Xapian 1.4.10, when called on a Query object which is OP_OR and has a reference count of 1, then o is appended as a new subquery (provided o is a different Query object and !o.empty()).

Definition at line 1005 of file query.h.

References add_subquery(), empty(), Xapian::Query::Internal::get_type(), internal, OP_OR, and Query().

◆ serialise()

string Xapian::Query::serialise ( ) const

Serialise this object into a string.

Definition at line 256 of file query.cc.

Referenced by DEFINE_TESTCASE(), and RemoteDatabase::set_query().

◆ unserialise()

const Query Xapian::Query::unserialise ( std::string_view  serialised,
const Registry reg = Registry() 
)
static

Unserialise a string and return a Query object.

Parameters
serialisedthe string to unserialise.
regXapian::Registry object to use to unserialise user-subclasses of Xapian::PostingSource (default: standard registry).

Definition at line 265 of file query.cc.

References AssertEq, p, Query(), and Xapian::Query::Internal::unserialise().

Referenced by DEFINE_TESTCASE(), and RemoteServer::msg_query().

Member Data Documentation

◆ internal

Xapian::Internal::intrusive_ptr<Internal> Xapian::Query::internal
private

◆ MatchAll

const Query Xapian::Query::MatchAll
static

A query matching all documents.

This is a static instance of Xapian::Query(std::string_view()). If you are constructing Query objects which use MatchAll in different threads then the reference counting of the static object can get messed up by concurrent access so you should instead use Xapian::Query(std::string_view()) directly.

Definition at line 75 of file query.h.

Referenced by DEFINE_TESTCASE(), TestRangeProcessor::operator()(), TitleFieldProcessor::operator()(), and HostFieldProcessor::operator()().

◆ MatchNothing

const Query Xapian::Query::MatchNothing
static

A query matching no documents.

This is a static instance of a default-constructed Xapian::Query object. It is safe to use concurrently from different threads, unlike MatchAll (this is because MatchNothing has a NULL internal object so there's no reference counting happening).

When combined with other Query objects using the various supported operators, MatchNothing works like false in boolean logic, so MatchNothing & q is MatchNothing, while MatchNothing | q is q.

Definition at line 64 of file query.h.

Referenced by add_subquery(), and DEFINE_TESTCASE().


The documentation for this class was generated from the following files: