Class QueryParserBase
java.lang.Object
org.apache.lucene.util.QueryBuilder
org.apache.lucene.queryparser.classic.QueryParserBase
- All Implemented Interfaces:
CommonQueryParserConfiguration
- Direct Known Subclasses:
QueryParser
public abstract class QueryParserBase
extends QueryBuilder
implements CommonQueryParserConfiguration
This class is overridden by QueryParser in QueryParser.jj
and acts to separate the majority of the Java code from the .jj grammar file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Do not catch this exception in your code, it means you are using methods that you should no longer use. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final QueryParser.Operator
Alternative form of QueryParser.Operator.ANDstatic final QueryParser.Operator
Alternative form of QueryParser.Operator.OR -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\
.boolean
boolean
final boolean
getDateResolution
(String fieldName) Returns the date resolution that is used by RangeQueries for the given field.Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.getField()
float
Get the minimal similarity for fuzzy queries.int
Get the prefix length for fuzzy queries.Returns current locale, allowing access by subclasses.boolean
int
Gets the default slop for phrases.void
Initializes a query parser.Parses a query string, returning aQuery
.abstract void
ReInit
(CharStream stream) void
setAllowLeadingWildcard
(boolean allowLeadingWildcard) Set totrue
to allow leading wildcard characters.void
setAnalyzeRangeTerms
(boolean analyzeRangeTerms) Set whether or not to analyze range terms when constructingTermRangeQuery
s.final void
setAutoGeneratePhraseQueries
(boolean value) Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text.void
setDateResolution
(String fieldName, DateTools.Resolution dateResolution) Sets the date resolution used by RangeQueries for a specific field.void
setDateResolution
(DateTools.Resolution dateResolution) Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set.void
Sets the boolean operator of the QueryParser.void
setFuzzyMinSim
(float fuzzyMinSim) Set the minimum similarity for fuzzy queries.void
setFuzzyPrefixLength
(int fuzzyPrefixLength) Set the prefix length for fuzzy queries.void
Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.void
setLowercaseExpandedTerms
(boolean lowercaseExpandedTerms) Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not.void
By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
when creating aPrefixQuery
,WildcardQuery
orTermRangeQuery
.void
setPhraseSlop
(int phraseSlop) Sets the default slop for phrases.void
setTimeZone
(TimeZone timeZone) abstract Query
TopLevelQuery
(String field) Methods inherited from class org.apache.lucene.util.QueryBuilder
createBooleanQuery, createBooleanQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, setAnalyzer, setEnablePositionIncrements
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
-
Field Details
-
AND_OPERATOR
Alternative form of QueryParser.Operator.AND -
OR_OPERATOR
Alternative form of QueryParser.Operator.OR
-
-
Method Details
-
init
Initializes a query parser. Called by the QueryParser constructor- Parameters:
matchVersion
- Lucene version to match. See here.f
- the default field for query terms.a
- used to find terms in the query text.
-
ReInit
-
TopLevelQuery
- Throws:
ParseException
-
parse
Parses a query string, returning aQuery
.- Parameters:
query
- the query string to be parsed.- Throws:
ParseException
- if the parsing fails
-
getField
- Returns:
- Returns the default field.
-
getAutoGeneratePhraseQueries
public final boolean getAutoGeneratePhraseQueries()- See Also:
-
setAutoGeneratePhraseQueries
public final void setAutoGeneratePhraseQueries(boolean value) Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text. NOTE: this behavior may not be suitable for all languages.Set to false if phrase queries should only be generated when surrounded by double quotes.
-
getFuzzyMinSim
public float getFuzzyMinSim()Get the minimal similarity for fuzzy queries.- Specified by:
getFuzzyMinSim
in interfaceCommonQueryParserConfiguration
-
setFuzzyMinSim
public void setFuzzyMinSim(float fuzzyMinSim) Set the minimum similarity for fuzzy queries. Default is 2f.- Specified by:
setFuzzyMinSim
in interfaceCommonQueryParserConfiguration
-
getFuzzyPrefixLength
public int getFuzzyPrefixLength()Get the prefix length for fuzzy queries.- Specified by:
getFuzzyPrefixLength
in interfaceCommonQueryParserConfiguration
- Returns:
- Returns the fuzzyPrefixLength.
-
setFuzzyPrefixLength
public void setFuzzyPrefixLength(int fuzzyPrefixLength) Set the prefix length for fuzzy queries. Default is 0.- Specified by:
setFuzzyPrefixLength
in interfaceCommonQueryParserConfiguration
- Parameters:
fuzzyPrefixLength
- The fuzzyPrefixLength to set.
-
setPhraseSlop
public void setPhraseSlop(int phraseSlop) Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.- Specified by:
setPhraseSlop
in interfaceCommonQueryParserConfiguration
-
getPhraseSlop
public int getPhraseSlop()Gets the default slop for phrases.- Specified by:
getPhraseSlop
in interfaceCommonQueryParserConfiguration
-
setAllowLeadingWildcard
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) Set totrue
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.
- Specified by:
setAllowLeadingWildcard
in interfaceCommonQueryParserConfiguration
-
getAllowLeadingWildcard
public boolean getAllowLeadingWildcard()- Specified by:
getAllowLeadingWildcard
in interfaceCommonQueryParserConfiguration
- See Also:
-
setDefaultOperator
Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR
) terms without any modifiers are considered optional: for examplecapital of Hungary
is equal tocapital OR of OR Hungary
.
InAND_OPERATOR
mode terms are considered to be in conjunction: the above mentioned query is parsed ascapital AND of AND Hungary
-
getDefaultOperator
Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR. -
setLowercaseExpandedTerms
public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default istrue
.- Specified by:
setLowercaseExpandedTerms
in interfaceCommonQueryParserConfiguration
-
getLowercaseExpandedTerms
public boolean getLowercaseExpandedTerms()- Specified by:
getLowercaseExpandedTerms
in interfaceCommonQueryParserConfiguration
- See Also:
-
setMultiTermRewriteMethod
By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
when creating aPrefixQuery
,WildcardQuery
orTermRangeQuery
. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids anyBooleanQuery.TooManyClauses
exception. However, if your application really needs to use the old-fashionedBooleanQuery
expansion rewriting and the above points are not relevant then use this to change the rewrite method.- Specified by:
setMultiTermRewriteMethod
in interfaceCommonQueryParserConfiguration
-
getMultiTermRewriteMethod
- Specified by:
getMultiTermRewriteMethod
in interfaceCommonQueryParserConfiguration
- See Also:
-
setLocale
Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.- Specified by:
setLocale
in interfaceCommonQueryParserConfiguration
-
getLocale
Returns current locale, allowing access by subclasses.- Specified by:
getLocale
in interfaceCommonQueryParserConfiguration
-
setTimeZone
- Specified by:
setTimeZone
in interfaceCommonQueryParserConfiguration
-
getTimeZone
- Specified by:
getTimeZone
in interfaceCommonQueryParserConfiguration
-
setDateResolution
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 withsetDateResolution(String, org.apache.lucene.document.DateTools.Resolution)
.- Specified by:
setDateResolution
in interfaceCommonQueryParserConfiguration
- Parameters:
dateResolution
- the default date resolution to set
-
setDateResolution
Sets the date resolution used by RangeQueries for a specific field.- Parameters:
fieldName
- field for which the date resolution is to be setdateResolution
- date resolution to set
-
getDateResolution
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. -
setAnalyzeRangeTerms
public void setAnalyzeRangeTerms(boolean analyzeRangeTerms) Set whether or not to analyze range terms when constructingTermRangeQuery
s. For example, setting this to true can enable analyzing terms into collation keys for locale-sensitiveTermRangeQuery
.- Parameters:
analyzeRangeTerms
- whether or not terms should be analyzed for RangeQuerys
-
getAnalyzeRangeTerms
public boolean getAnalyzeRangeTerms()- Returns:
- whether or not to analyze range terms when constructing
TermRangeQuery
s.
-
escape
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\
.
-