CLucene - a full-featured, c++ search engine
API Documentation
#include <MultiFieldQueryParser.h>
Public Member Functions | |
LUCENE_STATIC_CONSTANT (uint8_t, NORMAL_FIELD=0) | |
LUCENE_STATIC_CONSTANT (uint8_t, REQUIRED_FIELD=1) | |
LUCENE_STATIC_CONSTANT (uint8_t, PROHIBITED_FIELD=2) | |
MultiFieldQueryParser (const TCHAR **fields, lucene::analysis::Analyzer *a, BoostMap *boosts=NULL) | |
Creates a MultiFieldQueryParser. | |
virtual | ~MultiFieldQueryParser () |
Static Public Member Functions | |
static lucene::search::Query * | parse (const TCHAR *query, const TCHAR **fields, lucene::analysis::Analyzer *analyzer) |
static lucene::search::Query * | parse (const TCHAR *query, const TCHAR **fields, const uint8_t *flags, lucene::analysis::Analyzer *analyzer) |
Protected Member Functions | |
lucene::search::Query * | GetFieldQuery (const TCHAR *field, TCHAR *queryText) |
Returns a termquery, phrasequery for the specified field. | |
lucene::search::Query * | GetFieldQuery (const TCHAR *field, TCHAR *queryText, int32_t slop) |
Delegates to GetFieldQuery(string, string), and adds slop onto phrasequery. | |
lucene::search::Query * | GetFuzzyQuery (const TCHAR *field, TCHAR *termStr) |
Factory method for generating a query (similar to GetWildcardQuery). | |
lucene::search::Query * | GetRangeQuery (const TCHAR *field, TCHAR *part1, TCHAR *part2, bool inclusive) |
return NULL to disallow | |
lucene::search::Query * | GetPrefixQuery (const TCHAR *field, TCHAR *termStr) |
Factory method for generating a query (similar to GetWildcardQuery). | |
lucene::search::Query * | GetWildcardQuery (const TCHAR *field, TCHAR *termStr) |
Factory method for generating a query. | |
virtual lucene::search::Query * | QueryAddedCallback (const TCHAR *field, lucene::search::Query *query) |
A special virtual function for the MultiFieldQueryParser which can be used to clean up queries. | |
Protected Attributes | |
const TCHAR ** | fields |
BoostMap * | boosts |
lucene::queryParser::MultiFieldQueryParser::MultiFieldQueryParser | ( | const TCHAR ** | fields, | |
lucene::analysis::Analyzer * | a, | |||
BoostMap * | boosts = NULL | |||
) |
Creates a MultiFieldQueryParser.
It will, when parse(String query) is called, construct a query like this (assuming the query consists of two terms and you specify the two fields title
and body
):
(title:term1 body:term1) (title:term2 body:term2)
When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)
In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.
virtual lucene::queryParser::MultiFieldQueryParser::~MultiFieldQueryParser | ( | ) | [virtual] |
lucene::queryParser::MultiFieldQueryParser::LUCENE_STATIC_CONSTANT | ( | uint8_t | , | |
NORMAL_FIELD | = 0 | |||
) |
lucene::queryParser::MultiFieldQueryParser::LUCENE_STATIC_CONSTANT | ( | uint8_t | , | |
REQUIRED_FIELD | = 1 | |||
) |
lucene::queryParser::MultiFieldQueryParser::LUCENE_STATIC_CONSTANT | ( | uint8_t | , | |
PROHIBITED_FIELD | = 2 | |||
) |
static lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::parse | ( | const TCHAR * | query, | |
const TCHAR ** | fields, | |||
lucene::analysis::Analyzer * | analyzer | |||
) | [static] |
Parses a query which searches on the fields specified.
If x fields are specified, this effectively constructs:
(field1:query) (field2:query) (field3:query)...(fieldx:query)
query | Query string to parse | |
fields | Fields to search on | |
analyzer | Analyzer to use |
ParserException | if query parsing fails | |
TokenMgrError | if query parsing fails |
static lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::parse | ( | const TCHAR * | query, | |
const TCHAR ** | fields, | |||
const uint8_t * | flags, | |||
lucene::analysis::Analyzer * | analyzer | |||
) | [static] |
Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.
Usage:
String[] fields = {"filename", "contents", "description"};
int32_t[] flags = {MultiFieldQueryParser.NORMAL FIELD,
MultiFieldQueryParser.REQUIRED FIELD,
MultiFieldQueryParser.PROHIBITED FIELD,};
parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
query | Query string to parse | |
fields | Fields to search on | |
flags | Flags describing the fields | |
analyzer | Analyzer to use |
ParserException | if query parsing fails | |
TokenMgrError | if query parsing fails |
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetFieldQuery | ( | const TCHAR * | field, | |
TCHAR * | queryText | |||
) | [protected, virtual] |
Returns a termquery, phrasequery for the specified field.
Note: this is only a partial implementation, since MultiPhraseQuery is not implemented yet return NULL to disallow
Reimplemented from lucene::queryParser::QueryParserBase.
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetFieldQuery | ( | const TCHAR * | field, | |
TCHAR * | queryText, | |||
int32_t | slop | |||
) | [protected, virtual] |
Delegates to GetFieldQuery(string, string), and adds slop onto phrasequery.
Can be used to remove slop functionality
Reimplemented from lucene::queryParser::QueryParserBase.
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetFuzzyQuery | ( | const TCHAR * | field, | |
TCHAR * | termStr | |||
) | [protected, virtual] |
Factory method for generating a query (similar to GetWildcardQuery).
Called when parser parses an input term token that has the fuzzy suffix (~) appended.
field | Name of the field query will use. | |
termStr | Term token to use for building term for the query |
Reimplemented from lucene::queryParser::QueryParserBase.
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetRangeQuery | ( | const TCHAR * | field, | |
TCHAR * | part1, | |||
TCHAR * | part2, | |||
bool | inclusive | |||
) | [protected, virtual] |
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetPrefixQuery | ( | const TCHAR * | field, | |
TCHAR * | termStr | |||
) | [protected, virtual] |
Factory method for generating a query (similar to GetWildcardQuery).
Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.
Depending on settings, a prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.
Can be overridden by extending classes, to provide custom handling for wild card queries, which may be necessary due to missing analyzer calls.
field | Name of the field query will use. | |
termStr | Term token to use for building term for the query (without trailing '*' character!) |
Reimplemented from lucene::queryParser::QueryParserBase.
lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::GetWildcardQuery | ( | const TCHAR * | field, | |
TCHAR * | termStr | |||
) | [protected, virtual] |
Factory method for generating a query.
Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)
Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.
Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.
field | Name of the field query will use. | |
termStr | Term token that contains one or more wild card characters (? or *), but is not simple prefix term |
Reimplemented from lucene::queryParser::QueryParserBase.
virtual lucene:: search ::Query* lucene::queryParser::MultiFieldQueryParser::QueryAddedCallback | ( | const TCHAR * | field, | |
lucene::search::Query * | query | |||
) | [inline, protected, virtual] |
A special virtual function for the MultiFieldQueryParser which can be used to clean up queries.
Once the field name is known and the query has been created, its passed to this function. An example of this usage is to set boosts.
const TCHAR** lucene::queryParser::MultiFieldQueryParser::fields [protected] |