Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
Lucene::QueryParser Class Reference

The most important method is parse(const String&). More...

#include <QueryParser.h>

+ Inheritance diagram for Lucene::QueryParser:

Data Structures

struct  JJCalls
 

Public Types

enum  Operator { OR_OPERATOR , AND_OPERATOR }
 The default operator for parsing queries. Use QueryParser#setDefaultOperator to change it. More...
 
- Public Types inherited from Lucene::QueryParserConstants
enum  RegularExpressionId {
  _EOF = 0 , _NUM_CHAR = 1 , _ESCAPED_CHAR = 2 , _TERM_START_CHAR = 3 ,
  _TERM_CHAR = 4 , _WHITESPACE = 5 , _QUOTED_CHAR = 6 , AND = 8 ,
  OR = 9 , NOT = 10 , PLUS = 11 , MINUS = 12 ,
  LPAREN = 13 , RPAREN = 14 , COLON = 15 , STAR = 16 ,
  CARAT = 17 , QUOTED = 18 , TERM = 19 , FUZZY_SLOP = 20 ,
  PREFIXTERM = 21 , WILDTERM = 22 , RANGEIN_START = 23 , RANGEEX_START = 24 ,
  NUMBER = 25 , RANGEIN_TO = 26 , RANGEIN_END = 27 , RANGEIN_QUOTED = 28 ,
  RANGEIN_GOOP = 29 , RANGEEX_TO = 30 , RANGEEX_END = 31 , RANGEEX_QUOTED = 32 ,
  RANGEEX_GOOP = 33
}
 
enum  LexicalState { Boost = 0 , RangeEx = 1 , RangeIn = 2 , DEFAULT = 3 }
 

Public Member Functions

 QueryParser (LuceneVersion::Version matchVersion, const String &field, const AnalyzerPtr &analyzer)
 Constructs a query parser.
 
 QueryParser (const QueryParserCharStreamPtr &stream)
 Constructor with user supplied QueryParserCharStream.
 
 QueryParser (const QueryParserTokenManagerPtr &tokenMgr)
 Constructor with generated Token Manager.
 
virtual ~QueryParser ()
 
virtual String getClassName ()
 
boost::shared_ptr< QueryParsershared_from_this ()
 
QueryPtr parse (const String &query)
 Parses a query string, returning a Query.
 
AnalyzerPtr getAnalyzer ()
 
String getField ()
 
double getFuzzyMinSim ()
 Get the minimal similarity for fuzzy queries.
 
void setFuzzyMinSim (double fuzzyMinSim)
 Set the minimum similarity for fuzzy queries. Default is 0.5.
 
int32_t getFuzzyPrefixLength ()
 Get the prefix length for fuzzy queries.
 
void setFuzzyPrefixLength (int32_t fuzzyPrefixLength)
 Set the prefix length for fuzzy queries. Default is 0.
 
void setPhraseSlop (int32_t phraseSlop)
 Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
 
int32_t getPhraseSlop ()
 Gets the default slop for phrases.
 
void setAllowLeadingWildcard (bool allowLeadingWildcard)
 Set to true to allow leading wildcard characters.
 
bool getAllowLeadingWildcard ()
 
void setEnablePositionIncrements (bool enable)
 Set to true to enable position increments in result query.
 
bool getEnablePositionIncrements ()
 
void setDefaultOperator (Operator op)
 Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR) terms without any modifiers are considered optional: for example capital of Hungary is equal to capital OR of OR Hungary. In AND_OPERATOR mode terms are considered to be in conjunction: the above mentioned query is parsed as capital AND of AND Hungary.
 
Operator getDefaultOperator ()
 Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
 
void setLowercaseExpandedTerms (bool lowercaseExpandedTerms)
 Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.
 
bool getLowercaseExpandedTerms ()
 
void setMultiTermRewriteMethod (const RewriteMethodPtr &method)
 By default QueryParser uses MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyClauses" exception. However, if your application really needs to use the old- fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.
 
RewriteMethodPtr getMultiTermRewriteMethod ()
 
void setLocale (std::locale locale)
 Set locale used by date range parsing.
 
std::locale getLocale ()
 Returns current locale, allowing access by subclasses.
 
void setDateResolution (DateTools::Resolution dateResolution)
 Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with setDateResolution(const String&, DateTools::Resolution).
 
void setDateResolution (const String &fieldName, DateTools::Resolution dateResolution)
 Sets the date resolution used by RangeQueries for a specific field.
 
DateTools::Resolution getDateResolution (const String &fieldName)
 Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.
 
void setRangeCollator (const CollatorPtr &rc)
 Sets the collator used to determine index term inclusion in ranges for RangeQuerys.
 
CollatorPtr getRangeCollator ()
 
int32_t Conjunction ()
 Query ::= ( Clause )* Clause ::= ["+", "-"] [ ":"] ( | "(" Query ")" )
 
int32_t Modifiers ()
 
virtual QueryPtr TopLevelQuery (const String &field)
 This makes sure that there is no garbage after the query string.
 
virtual QueryPtr ParseQuery (const String &field)
 
virtual QueryPtr ParseClause (const String &field)
 
virtual QueryPtr ParseTerm (const String &field)
 
virtual void ReInit (const QueryParserCharStreamPtr &stream)
 Reinitialise.
 
virtual void ReInit (const QueryParserTokenManagerPtr &tokenMgr)
 Reinitialise.
 
virtual QueryParserTokenPtr getNextToken ()
 Get the next Token.
 
virtual QueryParserTokenPtr getToken (int32_t index)
 Get the specific Token.
 
virtual void generateParseException ()
 Generate QueryParserError exception.
 
virtual void enable_tracing ()
 Enable tracing.
 
virtual void disable_tracing ()
 Disable tracing.
 
- Public Member Functions inherited from Lucene::QueryParserConstants
virtual ~QueryParserConstants ()
 
- Public Member Functions inherited from Lucene::LuceneObject
virtual ~LuceneObject ()
 
virtual void initialize ()
 Called directly after instantiation to create objects that depend on this object being fully constructed.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Return clone of this object.
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual bool equals (const LuceneObjectPtr &other)
 Return whether two objects are equal.
 
virtual int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
virtual String toString ()
 Returns a string representation of the object.
 
- Public Member Functions inherited from Lucene::LuceneSync
virtual ~LuceneSync ()
 
virtual SynchronizePtr getSync ()
 Return this object synchronize lock.
 
virtual LuceneSignalPtr getSignal ()
 Return this object signal.
 
virtual void lock (int32_t timeout=0)
 Lock this object using an optional timeout.
 
virtual void unlock ()
 Unlock this object.
 
virtual bool holdsLock ()
 Returns true if this object is currently locked by current thread.
 
virtual void wait (int32_t timeout=0)
 Wait for signal using an optional timeout.
 
virtual void notifyAll ()
 Notify all threads waiting for signal.
 

Static Public Member Functions

static String _getClassName ()
 
static int main (Collection< String > args)
 Command line tool to test QueryParser, using SimpleAnalyzer.
 
- Static Public Member Functions inherited from Lucene::QueryParserConstants
static String _getClassName ()
 

Data Fields

bool lowercaseExpandedTerms
 
RewriteMethodPtr multiTermRewriteMethod
 
bool allowLeadingWildcard
 
bool enablePositionIncrements
 
AnalyzerPtr analyzer
 
String field
 
int32_t phraseSlop
 
double fuzzyMinSim
 
int32_t fuzzyPrefixLength
 
std::locale locale
 
DateTools::Resolution dateResolution
 
MapStringResolution fieldToDateResolution
 
CollatorPtr rangeCollator
 
QueryParserTokenManagerPtr token_source
 Generated Token Manager.
 
QueryParserTokenPtr token
 Current token.
 
QueryParserTokenPtr jj_nt
 Next token.
 

Protected Types

typedef boost::shared_ptr< JJCallsJJCallsPtr
 

Protected Member Functions

void ConstructParser (const QueryParserCharStreamPtr &stream, const QueryParserTokenManagerPtr &tokenMgr)
 Construct query parser with supplied QueryParserCharStream or TokenManager.
 
virtual void addClause (Collection< BooleanClausePtr > clauses, int32_t conj, int32_t mods, const QueryPtr &q)
 
virtual QueryPtr getFieldQuery (const String &field, const String &queryText)
 Use the analyzer to get all the tokens, and then build a TermQuery, PhraseQuery, or nothing based on the term count.
 
virtual QueryPtr getFieldQuery (const String &field, const String &queryText, int32_t slop)
 Base implementation delegates to getFieldQuery(const String&, const String&). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
 
virtual QueryPtr getRangeQuery (const String &field, const String &part1, const String &part2, bool inclusive)
 Builds a new TermRangeQuery instance for given min/max parts.
 
BooleanQueryPtr newBooleanQuery (bool disableCoord)
 Builds a new BooleanQuery instance.
 
BooleanClausePtr newBooleanClause (const QueryPtr &q, BooleanClause::Occur occur)
 Builds a new BooleanClause instance.
 
QueryPtr newTermQuery (const TermPtr &term)
 Builds a new TermQuery instance.
 
PhraseQueryPtr newPhraseQuery ()
 Builds a new PhraseQuery instance.
 
MultiPhraseQueryPtr newMultiPhraseQuery ()
 Builds a new MultiPhraseQuery instance.
 
QueryPtr newPrefixQuery (const TermPtr &prefix)
 Builds a new PrefixQuery instance.
 
QueryPtr newFuzzyQuery (const TermPtr &term, double minimumSimilarity, int32_t prefixLength)
 Builds a new FuzzyQuery instance.
 
QueryPtr newRangeQuery (const String &field, const String &part1, const String &part2, bool inclusive)
 Builds a new TermRangeQuery instance.
 
QueryPtr newMatchAllDocsQuery ()
 Builds a new MatchAllDocsQuery instance.
 
QueryPtr newWildcardQuery (const TermPtr &term)
 Builds a new WildcardQuery instance.
 
virtual QueryPtr getBooleanQuery (Collection< BooleanClausePtr > clauses)
 Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in.
 
virtual QueryPtr getBooleanQuery (Collection< BooleanClausePtr > clauses, bool disableCoord)
 Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in.
 
virtual QueryPtr getWildcardQuery (const String &field, const String &termStr)
 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)
 
virtual QueryPtr getPrefixQuery (const String &field, const String &termStr)
 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.
 
virtual QueryPtr getFuzzyQuery (const String &field, const String &termStr, double minSimilarity)
 Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that has the fuzzy suffix (~) appended.
 
String discardEscapeChar (const String &input)
 Returns a String where the escape char has been removed, or kept only once if there was a double escape. Supports escaped unicode characters, eg. translates \u0041 to A.
 
bool jj_2_1 (int32_t xla)
 
bool jj_3R_2 ()
 
bool jj_3_1 ()
 
bool jj_3R_3 ()
 
QueryParserTokenPtr jj_consume_token (int32_t kind)
 
bool jj_scan_token (int32_t kind)
 
int32_t jj_ntk ()
 
void jj_add_error_token (int32_t kind, int32_t pos)
 
void jj_rescan_token ()
 
void jj_save (int32_t index, int32_t xla)
 
- Protected Member Functions inherited from Lucene::QueryParserConstants
 QueryParserConstants ()
 
- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 

Static Protected Member Functions

static int32_t hexToInt (wchar_t c)
 Returns the numeric value of the hexadecimal character.
 
static String escape (const String &s)
 Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding .
 

Protected Attributes

Operator _operator
 The actual operator that parser uses to combine query terms.
 
int32_t _jj_ntk
 Next token.
 
QueryParserTokenPtr jj_scanpos
 
QueryParserTokenPtr jj_lastpos
 
int32_t jj_la
 
int32_t jj_gen
 
Collection< int32_t > jj_la1
 
Collection< JJCallsPtrjj_2_rtns
 
bool jj_rescan
 
int32_t jj_gc
 
Collection< Collection< int32_t > > jj_expentries
 
Collection< int32_t > jj_expentry
 
int32_t jj_kind
 
Collection< int32_t > jj_lasttokens
 
int32_t jj_endpos
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Static Protected Attributes

static const int32_t CONJ_NONE
 
static const int32_t CONJ_AND
 
static const int32_t CONJ_OR
 
static const int32_t MOD_NONE
 
static const int32_t MOD_NOT
 
static const int32_t MOD_REQ
 
static const int32_t jj_la1_0 []
 
static const int32_t jj_la1_1 []
 
- Static Protected Attributes inherited from Lucene::QueryParserConstants
static const wchar_t * _tokenImage []
 Literal token values.
 

Additional Inherited Members

- Static Public Attributes inherited from Lucene::QueryParserConstants
static Collection< String > tokenImage
 Literal token values.
 

Detailed Description

The most important method is parse(const String&).

The syntax for query strings is as follows: A Query is a series of clauses. A clause may be prefixed by:

A clause may be either:

Thus, in BNF, the query grammar is:

Query  ::= ( Clause )*
Clause ::= ["+", "-"] [ ":"] (  | "(" Query ")" )

Examples of appropriately formatted queries can be found in the query syntax documentation.

In TermRangeQuerys, QueryParser tries to detect date values, eg. date:[6/1/2005 TO 6/4/2005] produces a range query that searches for "date" fields between 2005-06-01 and 2005-06-04. Note that the format of the accepted input depends on the locale.

By default a date is converted into a search term using the deprecated DateField for compatibility reasons. To use the new DateTools to convert dates, a Resolution has to be set.

The date resolution that shall be used for RangeQueries can be set using setDateResolution(Resolution) or setDateResolution(const String&, Resolution). The former sets the default date resolution for all fields, whereas the latter can be used to set field specific date resolutions. Field specific date resolutions take, if set, precedence over the default date resolution.

If you use neither DateField nor DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites getRangeQuery(const String&, const String&, const String&, bool) to use a different method for date conversion.

Note that QueryParser is not thread-safe.

NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.

NOTE: You must specify the required Version compatibility when creating QueryParser:

Member Typedef Documentation

◆ JJCallsPtr

typedef boost::shared_ptr<JJCalls> Lucene::QueryParser::JJCallsPtr
protected

Member Enumeration Documentation

◆ Operator

The default operator for parsing queries. Use QueryParser#setDefaultOperator to change it.

Enumerator
OR_OPERATOR 
AND_OPERATOR 

Constructor & Destructor Documentation

◆ QueryParser() [1/3]

Lucene::QueryParser::QueryParser ( LuceneVersion::Version  matchVersion,
const String &  field,
const AnalyzerPtr analyzer 
)

Constructs a query parser.

Parameters
matchVersionLucene version to match.
fieldThe default field for query terms.
analyzerUsed to find terms in the query text.

◆ QueryParser() [2/3]

Lucene::QueryParser::QueryParser ( const QueryParserCharStreamPtr stream)

Constructor with user supplied QueryParserCharStream.

◆ QueryParser() [3/3]

Lucene::QueryParser::QueryParser ( const QueryParserTokenManagerPtr tokenMgr)

Constructor with generated Token Manager.

◆ ~QueryParser()

virtual Lucene::QueryParser::~QueryParser ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::QueryParser::_getClassName ( )
inlinestatic

◆ addClause()

virtual void Lucene::QueryParser::addClause ( Collection< BooleanClausePtr clauses,
int32_t  conj,
int32_t  mods,
const QueryPtr q 
)
protectedvirtual

◆ Conjunction()

int32_t Lucene::QueryParser::Conjunction ( )

Query ::= ( Clause )* Clause ::= ["+", "-"] [ ":"] ( | "(" Query ")" )

◆ ConstructParser()

void Lucene::QueryParser::ConstructParser ( const QueryParserCharStreamPtr stream,
const QueryParserTokenManagerPtr tokenMgr 
)
protected

Construct query parser with supplied QueryParserCharStream or TokenManager.

◆ disable_tracing()

virtual void Lucene::QueryParser::disable_tracing ( )
virtual

Disable tracing.

◆ discardEscapeChar()

String Lucene::QueryParser::discardEscapeChar ( const String &  input)
protected

Returns a String where the escape char has been removed, or kept only once if there was a double escape. Supports escaped unicode characters, eg. translates \u0041 to A.

◆ enable_tracing()

virtual void Lucene::QueryParser::enable_tracing ( )
virtual

Enable tracing.

◆ escape()

static String Lucene::QueryParser::escape ( const String &  s)
staticprotected

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding .

◆ generateParseException()

virtual void Lucene::QueryParser::generateParseException ( )
virtual

Generate QueryParserError exception.

◆ getAllowLeadingWildcard()

bool Lucene::QueryParser::getAllowLeadingWildcard ( )

◆ getAnalyzer()

AnalyzerPtr Lucene::QueryParser::getAnalyzer ( )
Returns
Returns the analyzer.

◆ getBooleanQuery() [1/2]

virtual QueryPtr Lucene::QueryParser::getBooleanQuery ( Collection< BooleanClausePtr clauses)
protectedvirtual

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in.

Can be overridden by extending classes, to modify query being returned.

Parameters
clausesList that contains BooleanClause instances to join.
Returns
Resulting Query object.

◆ getBooleanQuery() [2/2]

virtual QueryPtr Lucene::QueryParser::getBooleanQuery ( Collection< BooleanClausePtr clauses,
bool  disableCoord 
)
protectedvirtual

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in.

Can be overridden by extending classes, to modify query being returned.

Parameters
clausesList that contains BooleanClause instances to join.
disableCoordtrue if coord scoring should be disabled.
Returns
Resulting Query object.

◆ getClassName()

virtual String Lucene::QueryParser::getClassName ( )
inlinevirtual

Reimplemented from Lucene::QueryParserConstants.

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getDateResolution()

DateTools::Resolution Lucene::QueryParser::getDateResolution ( const String &  fieldName)

Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.

◆ getDefaultOperator()

Operator Lucene::QueryParser::getDefaultOperator ( )

Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.

◆ getEnablePositionIncrements()

bool Lucene::QueryParser::getEnablePositionIncrements ( )

◆ getField()

String Lucene::QueryParser::getField ( )
Returns
Returns the field.

◆ getFieldQuery() [1/2]

virtual QueryPtr Lucene::QueryParser::getFieldQuery ( const String &  field,
const String &  queryText 
)
protectedvirtual

Use the analyzer to get all the tokens, and then build a TermQuery, PhraseQuery, or nothing based on the term count.

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getFieldQuery() [2/2]

virtual QueryPtr Lucene::QueryParser::getFieldQuery ( const String &  field,
const String &  queryText,
int32_t  slop 
)
protectedvirtual

Base implementation delegates to getFieldQuery(const String&, const String&). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getFuzzyMinSim()

double Lucene::QueryParser::getFuzzyMinSim ( )

Get the minimal similarity for fuzzy queries.

◆ getFuzzyPrefixLength()

int32_t Lucene::QueryParser::getFuzzyPrefixLength ( )

Get the prefix length for fuzzy queries.

Returns
Returns the fuzzyPrefixLength.

◆ getFuzzyQuery()

virtual QueryPtr Lucene::QueryParser::getFuzzyQuery ( const String &  field,
const String &  termStr,
double  minSimilarity 
)
protectedvirtual

Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that has the fuzzy suffix (~) appended.

Parameters
fieldName of the field query will use.
termStrTerm token to use for building term for the query
Returns
Resulting Query built for the term

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getLocale()

std::locale Lucene::QueryParser::getLocale ( )

Returns current locale, allowing access by subclasses.

◆ getLowercaseExpandedTerms()

bool Lucene::QueryParser::getLowercaseExpandedTerms ( )

◆ getMultiTermRewriteMethod()

RewriteMethodPtr Lucene::QueryParser::getMultiTermRewriteMethod ( )

◆ getNextToken()

virtual QueryParserTokenPtr Lucene::QueryParser::getNextToken ( )
virtual

Get the next Token.

◆ getPhraseSlop()

int32_t Lucene::QueryParser::getPhraseSlop ( )

Gets the default slop for phrases.

◆ getPrefixQuery()

virtual QueryPtr Lucene::QueryParser::getPrefixQuery ( const String &  field,
const String &  termStr 
)
protectedvirtual

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.

Parameters
fieldName of the field query will use.
termStrTerm token to use for building term for the query (without trailing '*' character)
Returns
Resulting Query built for the term

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getRangeCollator()

CollatorPtr Lucene::QueryParser::getRangeCollator ( )
Returns
the collator used to determine index term inclusion in ranges for RangeQuerys.

◆ getRangeQuery()

virtual QueryPtr Lucene::QueryParser::getRangeQuery ( const String &  field,
const String &  part1,
const String &  part2,
bool  inclusive 
)
protectedvirtual

Builds a new TermRangeQuery instance for given min/max parts.

Reimplemented in Lucene::MultiFieldQueryParser.

◆ getToken()

virtual QueryParserTokenPtr Lucene::QueryParser::getToken ( int32_t  index)
virtual

Get the specific Token.

◆ getWildcardQuery()

virtual QueryPtr Lucene::QueryParser::getWildcardQuery ( const String &  field,
const String &  termStr 
)
protectedvirtual

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.

Parameters
fieldName of the field query will use.
termStrTerm token that contains one or more wild card characters (? or *), but is not simple prefix term
Returns
Resulting Query built for the term

Reimplemented in Lucene::MultiFieldQueryParser.

◆ hexToInt()

static int32_t Lucene::QueryParser::hexToInt ( wchar_t  c)
staticprotected

Returns the numeric value of the hexadecimal character.

◆ jj_2_1()

bool Lucene::QueryParser::jj_2_1 ( int32_t  xla)
protected

◆ jj_3_1()

bool Lucene::QueryParser::jj_3_1 ( )
protected

◆ jj_3R_2()

bool Lucene::QueryParser::jj_3R_2 ( )
protected

◆ jj_3R_3()

bool Lucene::QueryParser::jj_3R_3 ( )
protected

◆ jj_add_error_token()

void Lucene::QueryParser::jj_add_error_token ( int32_t  kind,
int32_t  pos 
)
protected

◆ jj_consume_token()

QueryParserTokenPtr Lucene::QueryParser::jj_consume_token ( int32_t  kind)
protected

◆ jj_ntk()

int32_t Lucene::QueryParser::jj_ntk ( )
protected

◆ jj_rescan_token()

void Lucene::QueryParser::jj_rescan_token ( )
protected

◆ jj_save()

void Lucene::QueryParser::jj_save ( int32_t  index,
int32_t  xla 
)
protected

◆ jj_scan_token()

bool Lucene::QueryParser::jj_scan_token ( int32_t  kind)
protected

◆ main()

static int Lucene::QueryParser::main ( Collection< String >  args)
static

Command line tool to test QueryParser, using SimpleAnalyzer.

◆ Modifiers()

int32_t Lucene::QueryParser::Modifiers ( )

◆ newBooleanClause()

BooleanClausePtr Lucene::QueryParser::newBooleanClause ( const QueryPtr q,
BooleanClause::Occur  occur 
)
protected

Builds a new BooleanClause instance.

Parameters
qsub query
occurhow this clause should occur when matching documents
Returns
new BooleanClause instance

◆ newBooleanQuery()

BooleanQueryPtr Lucene::QueryParser::newBooleanQuery ( bool  disableCoord)
protected

Builds a new BooleanQuery instance.

Parameters
disableCoorddisable coord

◆ newFuzzyQuery()

QueryPtr Lucene::QueryParser::newFuzzyQuery ( const TermPtr term,
double  minimumSimilarity,
int32_t  prefixLength 
)
protected

Builds a new FuzzyQuery instance.

Parameters
termTerm
minimumSimilarityminimum similarity
prefixLengthprefix length
Returns
new FuzzyQuery Instance

◆ newMatchAllDocsQuery()

QueryPtr Lucene::QueryParser::newMatchAllDocsQuery ( )
protected

Builds a new MatchAllDocsQuery instance.

Returns
new MatchAllDocsQuery instance

◆ newMultiPhraseQuery()

MultiPhraseQueryPtr Lucene::QueryParser::newMultiPhraseQuery ( )
protected

Builds a new MultiPhraseQuery instance.

Returns
new MultiPhraseQuery instance

◆ newPhraseQuery()

PhraseQueryPtr Lucene::QueryParser::newPhraseQuery ( )
protected

Builds a new PhraseQuery instance.

Returns
new PhraseQuery instance

◆ newPrefixQuery()

QueryPtr Lucene::QueryParser::newPrefixQuery ( const TermPtr prefix)
protected

Builds a new PrefixQuery instance.

Parameters
prefixPrefix term
Returns
new PrefixQuery instance

◆ newRangeQuery()

QueryPtr Lucene::QueryParser::newRangeQuery ( const String &  field,
const String &  part1,
const String &  part2,
bool  inclusive 
)
protected

Builds a new TermRangeQuery instance.

Parameters
fieldField
part1min
part2max
inclusivetrue if range is inclusive
Returns
new TermRangeQuery instance

◆ newTermQuery()

QueryPtr Lucene::QueryParser::newTermQuery ( const TermPtr term)
protected

Builds a new TermQuery instance.

Parameters
termterm
Returns
new TermQuery instance

◆ newWildcardQuery()

QueryPtr Lucene::QueryParser::newWildcardQuery ( const TermPtr term)
protected

Builds a new WildcardQuery instance.

Parameters
twildcard term
Returns
new WildcardQuery instance

◆ parse()

QueryPtr Lucene::QueryParser::parse ( const String &  query)

Parses a query string, returning a Query.

Parameters
queryThe query string to be parsed.

◆ ParseClause()

virtual QueryPtr Lucene::QueryParser::ParseClause ( const String &  field)
virtual

◆ ParseQuery()

virtual QueryPtr Lucene::QueryParser::ParseQuery ( const String &  field)
virtual

◆ ParseTerm()

virtual QueryPtr Lucene::QueryParser::ParseTerm ( const String &  field)
virtual

◆ ReInit() [1/2]

virtual void Lucene::QueryParser::ReInit ( const QueryParserCharStreamPtr stream)
virtual

Reinitialise.

◆ ReInit() [2/2]

virtual void Lucene::QueryParser::ReInit ( const QueryParserTokenManagerPtr tokenMgr)
virtual

Reinitialise.

◆ setAllowLeadingWildcard()

void Lucene::QueryParser::setAllowLeadingWildcard ( bool  allowLeadingWildcard)

Set to true to allow leading wildcard characters.

When set, * or ? are allowed as the first character of a PrefixQuery and WildcardQuery. Note that this can produce very slow queries on big indexes. Default: false.

◆ setDateResolution() [1/2]

void Lucene::QueryParser::setDateResolution ( const String &  fieldName,
DateTools::Resolution  dateResolution 
)

Sets the date resolution used by RangeQueries for a specific field.

Parameters
fieldNameField for which the date resolution is to be set
dateResolutionDate resolution to set

◆ setDateResolution() [2/2]

void Lucene::QueryParser::setDateResolution ( DateTools::Resolution  dateResolution)

Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with setDateResolution(const String&, DateTools::Resolution).

Parameters
dateResolutionThe default date resolution to set

◆ setDefaultOperator()

void Lucene::QueryParser::setDefaultOperator ( Operator  op)

Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR) terms without any modifiers are considered optional: for example capital of Hungary is equal to capital OR of OR Hungary. In AND_OPERATOR mode terms are considered to be in conjunction: the above mentioned query is parsed as capital AND of AND Hungary.

◆ setEnablePositionIncrements()

void Lucene::QueryParser::setEnablePositionIncrements ( bool  enable)

Set to true to enable position increments in result query.

When set, result phrase and multi-phrase queries will be aware of position increments. Useful when eg. a StopFilter increases the position increment of the token that follows an omitted token. Default: false.

◆ setFuzzyMinSim()

void Lucene::QueryParser::setFuzzyMinSim ( double  fuzzyMinSim)

Set the minimum similarity for fuzzy queries. Default is 0.5.

◆ setFuzzyPrefixLength()

void Lucene::QueryParser::setFuzzyPrefixLength ( int32_t  fuzzyPrefixLength)

Set the prefix length for fuzzy queries. Default is 0.

Parameters
fuzzyPrefixLengthThe fuzzyPrefixLength to set.

◆ setLocale()

void Lucene::QueryParser::setLocale ( std::locale  locale)

Set locale used by date range parsing.

◆ setLowercaseExpandedTerms()

void Lucene::QueryParser::setLowercaseExpandedTerms ( bool  lowercaseExpandedTerms)

Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.

◆ setMultiTermRewriteMethod()

void Lucene::QueryParser::setMultiTermRewriteMethod ( const RewriteMethodPtr method)

By default QueryParser uses MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyClauses" exception. However, if your application really needs to use the old- fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.

◆ setPhraseSlop()

void Lucene::QueryParser::setPhraseSlop ( int32_t  phraseSlop)

Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.

◆ setRangeCollator()

void Lucene::QueryParser::setRangeCollator ( const CollatorPtr rc)

Sets the collator used to determine index term inclusion in ranges for RangeQuerys.

WARNING: Setting the rangeCollator to a non-null collator using this method will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined. Depending on the number of index Terms in this Field, the operation could be very slow.

Parameters
rcThe collator to use when constructing RangeQuerys

◆ shared_from_this()

boost::shared_ptr< QueryParser > Lucene::QueryParser::shared_from_this ( )
inline

◆ TopLevelQuery()

virtual QueryPtr Lucene::QueryParser::TopLevelQuery ( const String &  field)
virtual

This makes sure that there is no garbage after the query string.

Field Documentation

◆ _jj_ntk

int32_t Lucene::QueryParser::_jj_ntk
protected

Next token.

◆ _operator

Operator Lucene::QueryParser::_operator
protected

The actual operator that parser uses to combine query terms.

◆ allowLeadingWildcard

bool Lucene::QueryParser::allowLeadingWildcard

◆ analyzer

AnalyzerPtr Lucene::QueryParser::analyzer

◆ CONJ_AND

const int32_t Lucene::QueryParser::CONJ_AND
staticprotected

◆ CONJ_NONE

const int32_t Lucene::QueryParser::CONJ_NONE
staticprotected

◆ CONJ_OR

const int32_t Lucene::QueryParser::CONJ_OR
staticprotected

◆ dateResolution

DateTools::Resolution Lucene::QueryParser::dateResolution

◆ enablePositionIncrements

bool Lucene::QueryParser::enablePositionIncrements

◆ field

String Lucene::QueryParser::field

◆ fieldToDateResolution

MapStringResolution Lucene::QueryParser::fieldToDateResolution

◆ fuzzyMinSim

double Lucene::QueryParser::fuzzyMinSim

◆ fuzzyPrefixLength

int32_t Lucene::QueryParser::fuzzyPrefixLength

◆ jj_2_rtns

Collection<JJCallsPtr> Lucene::QueryParser::jj_2_rtns
protected

◆ jj_endpos

int32_t Lucene::QueryParser::jj_endpos
protected

◆ jj_expentries

Collection< Collection<int32_t> > Lucene::QueryParser::jj_expentries
protected

◆ jj_expentry

Collection<int32_t> Lucene::QueryParser::jj_expentry
protected

◆ jj_gc

int32_t Lucene::QueryParser::jj_gc
protected

◆ jj_gen

int32_t Lucene::QueryParser::jj_gen
protected

◆ jj_kind

int32_t Lucene::QueryParser::jj_kind
protected

◆ jj_la

int32_t Lucene::QueryParser::jj_la
protected

◆ jj_la1

Collection<int32_t> Lucene::QueryParser::jj_la1
protected

◆ jj_la1_0

const int32_t Lucene::QueryParser::jj_la1_0[]
staticprotected

◆ jj_la1_1

const int32_t Lucene::QueryParser::jj_la1_1[]
staticprotected

◆ jj_lastpos

QueryParserTokenPtr Lucene::QueryParser::jj_lastpos
protected

◆ jj_lasttokens

Collection<int32_t> Lucene::QueryParser::jj_lasttokens
protected

◆ jj_nt

QueryParserTokenPtr Lucene::QueryParser::jj_nt

Next token.

◆ jj_rescan

bool Lucene::QueryParser::jj_rescan
protected

◆ jj_scanpos

QueryParserTokenPtr Lucene::QueryParser::jj_scanpos
protected

◆ locale

std::locale Lucene::QueryParser::locale

◆ lowercaseExpandedTerms

bool Lucene::QueryParser::lowercaseExpandedTerms

◆ MOD_NONE

const int32_t Lucene::QueryParser::MOD_NONE
staticprotected

◆ MOD_NOT

const int32_t Lucene::QueryParser::MOD_NOT
staticprotected

◆ MOD_REQ

const int32_t Lucene::QueryParser::MOD_REQ
staticprotected

◆ multiTermRewriteMethod

RewriteMethodPtr Lucene::QueryParser::multiTermRewriteMethod

◆ phraseSlop

int32_t Lucene::QueryParser::phraseSlop

◆ rangeCollator

CollatorPtr Lucene::QueryParser::rangeCollator

◆ token

QueryParserTokenPtr Lucene::QueryParser::token

Current token.

◆ token_source

QueryParserTokenManagerPtr Lucene::QueryParser::token_source

Generated Token Manager.


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

clucene.sourceforge.net