Xapian::QueryParser Class Reference

Build a Xapian::Query object from a user query string. More...

#include <queryparser.h>

List of all members.

Public Types

enum  feature_flag {
  FLAG_BOOLEAN = 1, FLAG_PHRASE = 2, FLAG_LOVEHATE = 4, FLAG_BOOLEAN_ANY_CASE = 8,
  FLAG_WILDCARD = 16, FLAG_PURE_NOT = 32, FLAG_PARTIAL = 64
}
 Enum of feature flags. More...
enum  stem_strategy { STEM_NONE, STEM_SOME, STEM_ALL }

Public Member Functions

 QueryParser (const QueryParser &o)
 Copy constructor.
QueryParseroperator= (const QueryParser &o)
 Assignment.
 QueryParser ()
 Default constructor.
 ~QueryParser ()
 Destructor.
void set_stemmer (const Xapian::Stem &stemmer)
 Set the stemmer.
void set_stemming_strategy (stem_strategy strategy)
 Set the stemming strategy.
void set_stopper (const Stopper *stop=NULL)
 Set the stopper.
void set_default_op (Query::op default_op)
 Set the default boolean operator.
Query::op get_default_op () const
 Get the default boolean operator.
void set_database (const Database &db)
 Specify the database being searched.
Query parse_query (const std::string &query_string, unsigned flags=FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE, const std::string &default_prefix="")
 Parse a query.
void add_prefix (const std::string &field, const std::string &prefix)
 Add a probabilistic term prefix.
void add_boolean_prefix (const std::string &field, const std::string &prefix)
 Add a boolean term prefix allowing the user to restrict a search with a boolean filter specified in the free text query.
TermIterator stoplist_begin () const
 Iterate over terms omitted from the query as stopwords.
TermIterator stoplist_end () const
TermIterator unstem_begin (const std::string &term) const
 Iterate over unstemmed forms of the given (stemmed) term used in the query.
TermIterator unstem_end (const std::string &) const
void add_valuerangeprocessor (Xapian::ValueRangeProcessor *vrproc)
 Register a ValueRangeProcessor.
std::string get_description () const
 Return a string describing this object.


Detailed Description

Build a Xapian::Query object from a user query string.


Member Enumeration Documentation

enum Xapian::QueryParser::feature_flag
 

Enum of feature flags.

Enumerator:
FLAG_BOOLEAN  Support AND, OR, etc and bracketed subexpressions.
FLAG_PHRASE  Support quoted phrases.
FLAG_LOVEHATE  Support + and -.
FLAG_BOOLEAN_ANY_CASE  Support AND, OR, etc even if they aren't in ALLCAPS.
FLAG_WILDCARD  Support right truncation (e.g.

Xap*).

NB: You need to tell the QueryParser object which database to expand wildcards from using set_database.

FLAG_PURE_NOT  Allow queries such as 'NOT apples'.

These require the use of a list of all documents in the database which is potentially expensive, so this feature isn't enabled by default.

FLAG_PARTIAL  Enable partial matching.

Partial matching causes the parser to treat the query as a "partially entered" search. This will automatically treat the final word as a wildcarded match, unless it is followed by whitespace, to produce more stable results from interactive searches.


Constructor & Destructor Documentation

Xapian::QueryParser::QueryParser const QueryParser o  ) 
 

Copy constructor.

Xapian::QueryParser::QueryParser  ) 
 

Default constructor.

Xapian::QueryParser::~QueryParser  ) 
 

Destructor.


Member Function Documentation

void Xapian::QueryParser::add_boolean_prefix const std::string &  field,
const std::string &  prefix
 

Add a boolean term prefix allowing the user to restrict a search with a boolean filter specified in the free text query.

E.g. qp.add_boolean_prefix("site", "H");

Allows the user to restrict a search with site:xapian.org which will be converted to Hxapian.org combined with any probabilistic query with OP_FILTER.

If multiple boolean filters are specified in a query for the same prefix, they will be combined with the OR operator. Then, if there are boolean filters for different prefixes, they will be combined with the AND operator.

Multiple fields can be mapped to the same prefix (so you can e.g. make site: and domain: aliases for each other). Instances of fields with different aliases but the same prefix will still be combined with the OR operator.

For example, if "site" and "domain" map to "H", but author maps to "A", a search for "site:Foo domain:Bar author:Fred" will map to "(Hfoo OR Hbar) AND Afred".

Parameters:
field The user visible field name
prefix The term prefix to map this to

void Xapian::QueryParser::add_prefix const std::string &  field,
const std::string &  prefix
 

Add a probabilistic term prefix.

E.g. qp.add_prefix("author", "A");

Allows the user to search for author:orwell which will search for the term "Aorwel" (assuming English stemming is in use). Multiple fields can be mapped to the same prefix (so you can e.g. make title: and subject: aliases for each other).

Parameters:
field The user visible field name
prefix The term prefix to map this to

void Xapian::QueryParser::add_valuerangeprocessor Xapian::ValueRangeProcessor vrproc  ) 
 

Register a ValueRangeProcessor.

Query::op Xapian::QueryParser::get_default_op  )  const
 

Get the default boolean operator.

std::string Xapian::QueryParser::get_description  )  const
 

Return a string describing this object.

QueryParser& Xapian::QueryParser::operator= const QueryParser o  ) 
 

Assignment.

Query Xapian::QueryParser::parse_query const std::string &  query_string,
unsigned  flags = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE,
const std::string &  default_prefix = ""
 

Parse a query.

Parameters:
query_string A free-text query as entered by a user
flags Zero or more Query::feature_flag specifying what features the QueryParser should support. Combine multiple values with bitwise-or (|).
default_prefix The default term prefix to use (default none). For example, you can pass "A" when parsing an "Author" field.

void Xapian::QueryParser::set_database const Database db  ) 
 

Specify the database being searched.

void Xapian::QueryParser::set_default_op Query::op  default_op  ) 
 

Set the default boolean operator.

void Xapian::QueryParser::set_stemmer const Xapian::Stem stemmer  ) 
 

Set the stemmer.

void Xapian::QueryParser::set_stemming_strategy stem_strategy  strategy  ) 
 

Set the stemming strategy.

void Xapian::QueryParser::set_stopper const Stopper stop = NULL  ) 
 

Set the stopper.

TermIterator Xapian::QueryParser::stoplist_begin  )  const
 

Iterate over terms omitted from the query as stopwords.

TermIterator Xapian::QueryParser::unstem_begin const std::string &  term  )  const
 

Iterate over unstemmed forms of the given (stemmed) term used in the query.


The documentation for this class was generated from the following file:
Documentation for Xapian (version 1.0.1).
Generated on 11 Jun 2007 by Doxygen 1.4.6.