Xapian::Query::Internal Class Reference

For internal use only.

Internal class, implementing most of Xapian::Query.

More...

#include <query.h>

Inheritance diagram for Xapian::Query::Internal:

Inheritance graph
[legend]
Collaboration diagram for Xapian::Query::Internal:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::vector< Internal * > subquery_list
 The container type for storing pointers to subqueries.
typedef int op_t
 Type storing the operation.

Public Member Functions

 Internal (const Query::Internal &copyme)
 Copy constructor.
void operator= (const Query::Internal &copyme)
 Assignment.
 Internal (const std::string &tname_, Xapian::termcount wqf_=1, Xapian::termpos term_pos_=0)
 A query consisting of a single term.
 Internal (op_t op_, Xapian::termcount parameter)
 Create internals given only the operator and a parameter.
 Internal (op_t op_, Xapian::valueno valno, const std::string &begin, const std::string &end)
 Construct a range query on a document value.
 Internal (op_t op_, Xapian::valueno valno, const std::string &value)
 Construct a value greater-than-or-equal query on a document value.
 ~Internal ()
 Destructor.
void add_subquery (const Query::Internal *subq)
 Add a subquery.
void set_dbl_parameter (double dbl_parameter_)
double get_dbl_parameter () const
Query::Internalend_construction ()
 Finish off the construction.
std::string serialise () const
 Return a string in an easily parsed form which contains all the information in a query.
std::string get_description () const
 Return a string describing this object.
Xapian::termcount get_parameter () const
 Get the numeric parameter used in this query.
Xapian::termcount get_length () const
 Get the length of the query, used by some ranking formulae.
TermIterator get_terms () const
 Return an iterator over all the terms in the query, in order of termpos.

Static Public Member Functions

static Xapian::Query::Internalunserialise (const std::string &s)

Static Public Attributes

static const int OP_LEAF = -1

Private Member Functions

void swap (Query::Internal &other)
 swap the contents of this with another Xapian::Query::Internal, in a way which is guaranteed not to throw.
void initialise_from_copy (const Query::Internal &copyme)
 Copy another Xapian::Query::Internal into self.
void accumulate_terms (std::vector< std::pair< std::string, Xapian::termpos > > &terms) const
Internalsimplify_query ()
 Simplify the query.
void validate_query () const
 Perform checks that query is valid.
bool simplify_matchnothing ()
 Simplify any matchnothing subqueries, either eliminating them, or setting this query to matchnothing, depending on the query operator.
void collapse_subqs ()
 Collapse the subqueries together if appropriate.
void flatten_subqs ()
 Flatten a query structure, by changing, for example, "A NEAR (B AND C)" to "(A NEAR B) AND (A NEAR C)".
std::string serialise (Xapian::termpos &curpos) const
 Implementation of serialisation; called recursively.

Static Private Member Functions

static std::string get_op_name (Xapian::Query::Internal::op_t op)
 Get a string describing the given query type.

Private Attributes

Xapian::Query::Internal::op_t op
 Operation to be performed at this node.
subquery_list subqs
 Sub queries on which to perform operation.
Xapian::termcount parameter
 For NEAR or PHRASE, how close terms must be to match: all terms within the operation must occur in a window of this size.
std::string tname
 Term that this node represents, or start of a range query.
std::string str_parameter
 Used to store the end of a range query.
Xapian::termpos term_pos
 Position in query of this term - leaf node only.
Xapian::termcount wqf
 Within query frequency of this term - leaf node only.

Friends

class ::LocalSubMatch
class ::MultiMatch
class ::QueryOptimiser
struct ::SortPosName
class Query

Detailed Description

For internal use only.

Internal class, implementing most of Xapian::Query.

Definition at line 278 of file query.h.


Member Typedef Documentation

typedef std::vector<Internal *> Xapian::Query::Internal::subquery_list

The container type for storing pointers to subqueries.

Definition at line 288 of file query.h.

typedef int Xapian::Query::Internal::op_t

Type storing the operation.

Definition at line 291 of file query.h.


Constructor & Destructor Documentation

Xapian::Query::Internal::Internal ( const Query::Internal copyme  ) 

Copy constructor.

Definition at line 590 of file omqueryinternal.cc.

References subqs.

Xapian::Query::Internal::Internal ( const std::string &  tname_,
Xapian::termcount  wqf_ = 1,
Xapian::termpos  term_pos_ = 0 
) [explicit]

A query consisting of a single term.

Xapian::Query::Internal::Internal ( op_t  op_,
Xapian::termcount  parameter 
)

Create internals given only the operator and a parameter.

Definition at line 622 of file omqueryinternal.cc.

References Xapian::Query::OP_ELITE_SET, Xapian::Query::OP_NEAR, Xapian::Query::OP_PHRASE, and parameter.

Xapian::Query::Internal::Internal ( op_t  op_,
Xapian::valueno  valno,
const std::string &  begin,
const std::string &  end 
)

Construct a range query on a document value.

Xapian::Query::Internal::Internal ( op_t  op_,
Xapian::valueno  valno,
const std::string &  value 
)

Construct a value greater-than-or-equal query on a document value.

Definition at line 646 of file omqueryinternal.cc.

References OP_LEAF, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, parameter, term_pos, validate_query(), and wqf.

Xapian::Query::Internal::~Internal (  ) 

Destructor.

Definition at line 664 of file omqueryinternal.cc.

References subqs.


Member Function Documentation

void Xapian::Query::Internal::swap ( Query::Internal other  )  [private]

swap the contents of this with another Xapian::Query::Internal, in a way which is guaranteed not to throw.

This is used with the assignment operator to make it exception safe. It's important to adjust swap with any addition of member variables!

Definition at line 579 of file omqueryinternal.cc.

References op, parameter, str_parameter, subqs, term_pos, tname, and wqf.

Referenced by flatten_subqs().

void Xapian::Query::Internal::initialise_from_copy ( const Query::Internal copyme  )  [private]

Copy another Xapian::Query::Internal into self.

void Xapian::Query::Internal::accumulate_terms ( std::vector< std::pair< std::string, Xapian::termpos > > &  terms  )  const [private]

Referenced by get_terms().

Xapian::Query::Internal * Xapian::Query::Internal::simplify_query (  )  [private]

Simplify the query.

For example, an AND query with only one subquery would become the subquery itself.

Definition at line 776 of file omqueryinternal.cc.

References Assert, collapse_subqs(), DEBUGCALL, flatten_subqs(), get_dbl_parameter(), Xapian::Query::OP_AND, Xapian::Query::OP_ELITE_SET, OP_LEAF, Xapian::Query::OP_NEAR, Xapian::Query::OP_OR, Xapian::Query::OP_PHRASE, Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, Xapian::Query::OP_VALUE_RANGE, Xapian::Query::OP_XOR, parameter, simplify_matchnothing(), str_parameter, subqs, and tname.

Referenced by end_construction().

void Xapian::Query::Internal::validate_query (  )  const [private]

Perform checks that query is valid.

(eg, has correct number of sub queries.) Throw an exception if not. This is initially called on the query before any simplifications have been made, and after simplications.

Definition at line 683 of file omqueryinternal.cc.

References Assert, DEBUGCALL, get_dbl_parameter(), get_max_subqs(), get_min_subqs(), get_op_name(), is_leaf(), om_tostring(), Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, Xapian::Query::OP_VALUE_RANGE, subqs, and tname.

Referenced by end_construction(), Internal(), and MultiMatch::MultiMatch().

bool Xapian::Query::Internal::simplify_matchnothing (  )  [private]

Simplify any matchnothing subqueries, either eliminating them, or setting this query to matchnothing, depending on the query operator.

Returns true if simplification resulted in a matchnothing query.

Definition at line 711 of file omqueryinternal.cc.

References Assert, Xapian::Query::OP_AND, Xapian::Query::OP_AND_MAYBE, Xapian::Query::OP_AND_NOT, Xapian::Query::OP_ELITE_SET, Xapian::Query::OP_FILTER, OP_LEAF, Xapian::Query::OP_NEAR, Xapian::Query::OP_OR, Xapian::Query::OP_PHRASE, Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_XOR, and subqs.

Referenced by simplify_query().

string Xapian::Query::Internal::get_op_name ( Xapian::Query::Internal::op_t  op  )  [static, private]

Get a string describing the given query type.

Definition at line 215 of file omqueryinternal.cc.

References Xapian::Query::OP_AND, Xapian::Query::OP_AND_MAYBE, Xapian::Query::OP_AND_NOT, Xapian::Query::OP_ELITE_SET, Xapian::Query::OP_FILTER, OP_LEAF, Xapian::Query::OP_NEAR, Xapian::Query::OP_OR, Xapian::Query::OP_PHRASE, Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, Xapian::Query::OP_VALUE_RANGE, and Xapian::Query::OP_XOR.

Referenced by get_description(), and validate_query().

void Xapian::Query::Internal::collapse_subqs (  )  [private]

Collapse the subqueries together if appropriate.

Definition at line 862 of file omqueryinternal.cc.

References Assert, AssertEq, is_leaf(), Xapian::Query::OP_AND, Xapian::Query::OP_OR, Xapian::Query::OP_XOR, and subqs.

Referenced by simplify_query().

void Xapian::Query::Internal::flatten_subqs (  )  [private]

Flatten a query structure, by changing, for example, "A NEAR (B AND C)" to "(A NEAR B) AND (A NEAR C)".

Definition at line 895 of file omqueryinternal.cc.

References add_subquery(), Assert, end_construction(), is_leaf(), Xapian::Query::OP_NEAR, Xapian::Query::OP_PHRASE, subqs, and swap().

Referenced by simplify_query().

string Xapian::Query::Internal::serialise ( Xapian::termpos curpos  )  const [private]

Implementation of serialisation; called recursively.

The format is designed to be relatively easy to parse.

A single-term query becomes `[<encodedtname><termpos>#<wqf>' where: <wqf> is the decimal within query frequency (1 if omitted), <termpos> is the decimal term position (index of term if omitted).

A compound query becomes `(<subqueries><op>', where: <subqueries> is the list of subqueries <op> is one of: &|+-^ also ~N "N >F *N (N unsigned int; F floating point)

If querylen != sum(wqf) we append `=len' (at present we always do this for compound queries as it's simpler than working out what sum(wqf) would be - FIXME).

Definition at line 131 of file omqueryinternal.cc.

References Assert, encode_length(), om_tostring(), Xapian::Query::OP_AND, Xapian::Query::OP_AND_MAYBE, Xapian::Query::OP_AND_NOT, Xapian::Query::OP_ELITE_SET, Xapian::Query::OP_FILTER, OP_LEAF, Xapian::Query::OP_NEAR, Xapian::Query::OP_OR, Xapian::Query::OP_PHRASE, Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, Xapian::Query::OP_VALUE_RANGE, Xapian::Query::OP_XOR, parameter, str_parameter, subqs, term_pos, tname, and wqf.

void Xapian::Query::Internal::operator= ( const Query::Internal copyme  ) 

Assignment.

static Xapian::Query::Internal* Xapian::Query::Internal::unserialise ( const std::string &  s  )  [static]

Referenced by test_serialisequery1().

void Xapian::Query::Internal::add_subquery ( const Query::Internal subq  ) 

Add a subquery.

Definition at line 936 of file omqueryinternal.cc.

References Assert, is_leaf(), op, Xapian::Query::OP_AND, Xapian::Query::OP_OR, Xapian::Query::OP_XOR, and subqs.

Referenced by flatten_subqs(), and qint_from_vector().

void Xapian::Query::Internal::set_dbl_parameter ( double  dbl_parameter_  ) 

Definition at line 953 of file omqueryinternal.cc.

References serialise_double(), and str_parameter.

Referenced by qint_from_vector().

double Xapian::Query::Internal::get_dbl_parameter (  )  const

Definition at line 963 of file omqueryinternal.cc.

References str_parameter, and unserialise_double().

Referenced by get_description(), simplify_query(), and validate_query().

Xapian::Query::Internal * Xapian::Query::Internal::end_construction (  ) 

Finish off the construction.

Definition at line 673 of file omqueryinternal.cc.

References DEBUGCALL, simplify_query(), and validate_query().

Referenced by flatten_subqs(), and qint_from_vector().

std::string Xapian::Query::Internal::serialise (  )  const [inline]

Return a string in an easily parsed form which contains all the information in a query.

Definition at line 420 of file query.h.

string Xapian::Query::Internal::get_description (  )  const

Return a string describing this object.

Definition at line 238 of file omqueryinternal.cc.

References get_dbl_parameter(), get_op_name(), is_leaf(), om_tostring(), Xapian::Query::OP_ELITE_SET, Xapian::Query::OP_NEAR, Xapian::Query::OP_PHRASE, Xapian::Query::OP_SCALE_WEIGHT, Xapian::Query::OP_VALUE_GE, Xapian::Query::OP_VALUE_LE, Xapian::Query::OP_VALUE_RANGE, parameter, str_parameter, subqs, term_pos, tname, and wqf.

Xapian::termcount Xapian::Query::Internal::get_parameter (  )  const [inline]

Get the numeric parameter used in this query.

This is used by the QueryParser to get the value number for VALUE_RANGE queries. It should be replaced by a public method on the Query class at some point, but the API which should be used for that is unclear, so this is a temporary workaround.

Definition at line 435 of file query.h.

Xapian::termcount Xapian::Query::Internal::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().

Definition at line 300 of file omqueryinternal.cc.

References is_leaf(), subqs, and wqf.

Xapian::TermIterator Xapian::Query::Internal::get_terms (  )  const

Return an iterator over 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.

Definition at line 340 of file omqueryinternal.cc.

References accumulate_terms().

Referenced by LocalSubMatch::prepare_match().


Friends And Related Function Documentation

friend class ::LocalSubMatch [friend]

Definition at line 279 of file query.h.

friend class ::MultiMatch [friend]

Definition at line 280 of file query.h.

friend class ::QueryOptimiser [friend]

Definition at line 281 of file query.h.

friend struct ::SortPosName [friend]

Definition at line 282 of file query.h.

friend class Query [friend]

Definition at line 283 of file query.h.


Member Data Documentation

const int Xapian::Query::Internal::OP_LEAF = -1 [static]

Definition at line 285 of file query.h.

Referenced by QueryOptimiser::do_subquery(), get_max_subqs(), get_min_subqs(), get_op_name(), Internal(), is_leaf(), LocalSubMatch::postlist_from_op_leaf_query(), serialise(), simplify_matchnothing(), and simplify_query().

Xapian::Query::Internal::op_t Xapian::Query::Internal::op [private]

Operation to be performed at this node.

Definition at line 295 of file query.h.

Referenced by add_subquery(), SortPosName::operator()(), and swap().

subquery_list Xapian::Query::Internal::subqs [private]

Sub queries on which to perform operation.

Definition at line 298 of file query.h.

Referenced by add_subquery(), collapse_subqs(), flatten_subqs(), get_description(), get_length(), Internal(), serialise(), simplify_matchnothing(), simplify_query(), swap(), validate_query(), and ~Internal().

Xapian::termcount Xapian::Query::Internal::parameter [private]

For NEAR or PHRASE, how close terms must be to match: all terms within the operation must occur in a window of this size.

For ELITE_SET, the number of terms to select from those specified.

For RANGE, the value number to apply the range test to.

Definition at line 307 of file query.h.

Referenced by get_description(), Internal(), serialise(), simplify_query(), and swap().

std::string Xapian::Query::Internal::tname [private]

Term that this node represents, or start of a range query.

For a leaf node, this holds the term name. For an OP_VALUE_RANGE query this holds the start of the range. For an OP_VALUE_GE or OP_VALUE_LE query this holds the value to compare against.

Definition at line 315 of file query.h.

Referenced by get_description(), SortPosName::operator()(), serialise(), simplify_query(), swap(), and validate_query().

std::string Xapian::Query::Internal::str_parameter [private]

Used to store the end of a range query.

Definition at line 318 of file query.h.

Referenced by get_dbl_parameter(), get_description(), serialise(), set_dbl_parameter(), simplify_query(), and swap().

Xapian::termpos Xapian::Query::Internal::term_pos [private]

Position in query of this term - leaf node only.

Definition at line 321 of file query.h.

Referenced by get_description(), Internal(), SortPosName::operator()(), serialise(), and swap().

Xapian::termcount Xapian::Query::Internal::wqf [private]

Within query frequency of this term - leaf node only.

Definition at line 324 of file query.h.

Referenced by get_description(), get_length(), Internal(), serialise(), and swap().


The documentation for this class was generated from the following files:
Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.