# Xapian::Query Class Reference

Class representing a query. More...

List of all members.

## Public Types
enum | op { OP_AND, OP_OR, OP_AND_NOT, OP_XOR, OP_AND_MAYBE, OP_FILTER, OP_NEAR, OP_PHRASE, OP_VALUE_RANGE, OP_SCALE_WEIGHT, OP_ELITE_SET, OP_VALUE_GE, OP_VALUE_LE }
| Enum of possible query operations. More...
## Public Member Functions
| Query (const Query &copyme)
| Copy constructor.
Query & | operator= (const Query &copyme)
| Assignment.
| Query ()
| Default constructor: makes an empty query which matches no documents.
| ~Query ()
| Destructor.
| Query (const std::string &tname_, Xapian::termcount wqf_=1, Xapian::termpos pos_=0)
| A query consisting of a single term.
| Query (Query::op op_, const Query &left, const Query &right)
| A query consisting of two subqueries, opp-ed together.
| Query (Query::op op_, const std::string &left, const std::string &right)
| A query consisting of two termnames opp-ed together.
template<class Iterator >
| Query (Query::op op_, Iterator qbegin, Iterator qend, Xapian::termcount parameter=0)
| Combine a number of Xapian::Query-s with the specified operator.
| Query (Query::op op_, Xapian::Query q)
| Apply the specified operator to a single Xapian::Query object.
| Query (Query::op op_, Xapian::Query q, double parameter)
| Apply the specified operator to a single Xapian::Query object, with a double parameter.
| Query (Query::op op_, Xapian::valueno valno, const std::string &begin, const std::string &end)
| Construct a value range query on a document value.
| Query (Query::op op_, Xapian::valueno valno, const std::string &value)
| Construct a value comparison query on a document value.
Xapian::termcount | get_length () const
| Get the length of the query, used by some ranking formulae.
TermIterator | get_terms_begin () const
| Return a Xapian::TermIterator returning all the terms in the query, in order of termpos.
TermIterator | get_terms_end () const
| Return a Xapian::TermIterator to the end of the list of terms in the query.
bool | empty () const
| Test if the query is empty (i.e.
std::string | get_description () const
| Return a string describing this object.
## Static Public Attributes
static Xapian::Query | MatchAll
| A query which matches all documents in the database.
static Xapian::Query | MatchNothing
| A query which matches no documents.

## Detailed Description

Class representing a query.

Queries are represented as a tree of objects.

## Member Enumeration Documentation

enum Xapian::Query::op

Enum of possible query operations.

Enumerator:

  OP_AND | Return iff both subqueries are satisfied.
  OP_OR | Return if either subquery is satisfied.
  OP_AND_NOT | Return if left but not right satisfied.
  OP_XOR | Return if one query satisfied, but not both.
  OP_AND_MAYBE | Return iff left satisfied, but use weights from both.
  OP_FILTER | As AND, but use only weights from left subquery.
  OP_NEAR | Find occurrences of a list of terms with all the terms occurring within a specified window of positions. Each occurrence of a term must be at a different position, but the order they appear in is irrelevant. The window parameter should be specified for this operation, but will default to the number of terms in the list.
  OP_PHRASE | Find occurrences of a list of terms with all the terms occurring within a specified window of positions, and all the terms appearing in the order specified. Each occurrence of a term must be at a different position. The window parameter should be specified for this operation, but will default to the number of terms in the list.
  OP_VALUE_RANGE | Filter by a range test on a document value.
  OP_SCALE_WEIGHT | Scale the weight of a subquery by the specified factor. A factor of 0 means this subquery will contribute no weight to the query - it will act as a purely boolean subquery. If the factor is negative, Xapian::InvalidArgumentError will be thrown.
  OP_ELITE_SET | Select an elite set from the subqueries, and perform a query with these combined as an OR query.
  OP_VALUE_GE | Filter by a greater-than-or-equal test on a document value.
  OP_VALUE_LE | Filter by a less-than-or-equal test on a document value.

## Constructor & Destructor Documentation

Xapian::Query::Query | ( | const Query & | copyme | ) |

Copy constructor.

Xapian::Query::Query | ( |  | ) |

Default constructor: makes an empty query which matches no documents.

Also useful for defining a Query object to be assigned to later.

An exception will be thrown if an attempt is made to use an undefined query when building up a composite query.

Xapian::Query::~Query | ( |  | ) |

Destructor.

Xapian::Query::Query | ( | const std::string & | tname_,
|  | Xapian::termcount | wqf_ = `1`,
|  | Xapian::termpos | pos_ = `0` |
| ) |  |  |

A query consisting of a single term.

Xapian::Query::Query | ( | Query::op | op_,
|  | const Query & | left,
|  | const Query & | right |
| ) |  |  |

A query consisting of two subqueries, opp-ed together.

Xapian::Query::Query | ( | Query::op | op_,
|  | const std::string & | left,
|  | const std::string & | right |
| ) |  |  |

A query consisting of two termnames opp-ed together.

template<class Iterator >

Xapian::Query::Query | ( | Query::op | op_,
|  | Iterator | qbegin,
|  | Iterator | qend,
|  | Xapian::termcount | parameter = `0` |
| ) |  |  | `[inline]`

Combine a number of Xapian::Query-s with the specified operator.

The Xapian::Query objects are specified with begin and end iterators.

AND, OR, NEAR and PHRASE can take any number of subqueries. Other operators take exactly two subqueries.

The iterators may be to Xapian::Query objects, pointers to Xapian::Query objects, or termnames (std::string-s).

For NEAR and PHRASE, a window size can be specified in parameter.

For ELITE_SET, the elite set size can be specified in parameter.

Xapian::Query::Query | ( | Query::op | op_,
|  | Xapian::Query | q |
| ) |  |  |

Apply the specified operator to a single Xapian::Query object.

Deprecated:
  This method is deprecated because it isn't useful, since none of the current query operators can be usefully applied to a single subquery without a parameter value.

Xapian::Query::Query | ( | Query::op | op_,
|  | Xapian::Query | q,
|  | double | parameter |
| ) |  |  |

Apply the specified operator to a single Xapian::Query object, with a double parameter.

Xapian::Query::Query | ( | Query::op | op_,
|  | Xapian::valueno | valno,
|  | const std::string & | begin,
|  | const std::string & | end |
| ) |  |  |

Construct a value range query on a document value.

A value range query matches those documents which have a value stored in the slot given by valno which is in the range specified by begin and end (in lexicographical order), including the endpoints.

Parameters:

  | op_ | The operator to use for the query. Currently, must be OP_VALUE_RANGE.
  | valno | The slot number to get the value from.
  | begin | The start of the range.
  | end | The end of the range.

Xapian::Query::Query | ( | Query::op | op_,
|  | Xapian::valueno | valno,
|  | const std::string & | value |
| ) |  |  |

Construct a value comparison query on a document value.

This query matches those documents which have a value stored in the slot given by valno which compares, as specified by the operator, to value.

Parameters:

  | op_ | The operator to use for the query. Currently, must be OP_VALUE_GE or OP_VALUE_LE.
  | valno | The slot number to get the value from.
  | value | The value to compare.

## Member Function Documentation

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

Test if the query is empty (i.e.

was constructed using the default ctor or with an empty iterator ctor).

std::string Xapian::Query::get_description | ( |  | ) | const

Return a string describing this object.

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

Get the length of the query, used by some ranking formulae.

This value is calculated automatically - if you want to override it you can pass a different value to Enquire::set_query().

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

Return a Xapian::TermIterator returning all the terms in the query, in order of termpos.

If multiple terms have the same term position, their order is unspecified. Duplicates (same term and termpos) will be removed.

TermIterator Xapian::Query::get_terms_end | ( |  | ) | const`[inline]`

Return a Xapian::TermIterator to the end of the list of terms in the query.

Query& Xapian::Query::operator= | ( | const Query & | copyme | ) |

Assignment.

## Member Data Documentation

Xapian::Query Xapian::Query::MatchAll`[static]`

A query which matches all documents in the database.

Xapian::Query Xapian::Query::MatchNothing`[static]`

A query which matches no documents.

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

- xapian/query.h