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 classDo 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.OperatorAlternative form of QueryParser.Operator.ANDstatic final QueryParser.OperatorAlternative form of QueryParser.Operator.OR -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.booleanbooleanfinal booleangetDateResolution(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()floatGet the minimal similarity for fuzzy queries.intGet the prefix length for fuzzy queries.Returns current locale, allowing access by subclasses.booleanintGets the default slop for phrases.voidInitializes a query parser.Parses a query string, returning aQuery.abstract voidReInit(CharStream stream) voidsetAllowLeadingWildcard(boolean allowLeadingWildcard) Set totrueto allow leading wildcard characters.voidsetAnalyzeRangeTerms(boolean analyzeRangeTerms) Set whether or not to analyze range terms when constructingTermRangeQuerys.final voidsetAutoGeneratePhraseQueries(boolean value) Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text.voidsetDateResolution(String fieldName, DateTools.Resolution dateResolution) Sets the date resolution used by RangeQueries for a specific field.voidsetDateResolution(DateTools.Resolution dateResolution) Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set.voidSets the boolean operator of the QueryParser.voidsetFuzzyMinSim(float fuzzyMinSim) Set the minimum similarity for fuzzy queries.voidsetFuzzyPrefixLength(int fuzzyPrefixLength) Set the prefix length for fuzzy queries.voidSet locale used by date range parsing, lowercasing, and other locale-sensitive operations.voidsetLowercaseExpandedTerms(boolean lowercaseExpandedTerms) Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not.voidBy default QueryParser usesMultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULTwhen creating aPrefixQuery,WildcardQueryorTermRangeQuery.voidsetPhraseSlop(int phraseSlop) Sets the default slop for phrases.voidsetTimeZone(TimeZone timeZone) abstract QueryTopLevelQuery(String field) Methods inherited from class org.apache.lucene.util.QueryBuilder
createBooleanQuery, createBooleanQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, setAnalyzer, setEnablePositionIncrementsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
getFuzzyMinSimin interfaceCommonQueryParserConfiguration
-
setFuzzyMinSim
public void setFuzzyMinSim(float fuzzyMinSim) Set the minimum similarity for fuzzy queries. Default is 2f.- Specified by:
setFuzzyMinSimin interfaceCommonQueryParserConfiguration
-
getFuzzyPrefixLength
public int getFuzzyPrefixLength()Get the prefix length for fuzzy queries.- Specified by:
getFuzzyPrefixLengthin interfaceCommonQueryParserConfiguration- Returns:
- Returns the fuzzyPrefixLength.
-
setFuzzyPrefixLength
public void setFuzzyPrefixLength(int fuzzyPrefixLength) Set the prefix length for fuzzy queries. Default is 0.- Specified by:
setFuzzyPrefixLengthin 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:
setPhraseSlopin interfaceCommonQueryParserConfiguration
-
getPhraseSlop
public int getPhraseSlop()Gets the default slop for phrases.- Specified by:
getPhraseSlopin interfaceCommonQueryParserConfiguration
-
setAllowLeadingWildcard
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) Set totrueto 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:
setAllowLeadingWildcardin interfaceCommonQueryParserConfiguration
-
getAllowLeadingWildcard
public boolean getAllowLeadingWildcard()- Specified by:
getAllowLeadingWildcardin 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 Hungaryis equal tocapital OR of OR Hungary.
InAND_OPERATORmode 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:
setLowercaseExpandedTermsin interfaceCommonQueryParserConfiguration
-
getLowercaseExpandedTerms
public boolean getLowercaseExpandedTerms()- Specified by:
getLowercaseExpandedTermsin interfaceCommonQueryParserConfiguration- See Also:
-
setMultiTermRewriteMethod
By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULTwhen creating aPrefixQuery,WildcardQueryorTermRangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids anyBooleanQuery.TooManyClausesexception. However, if your application really needs to use the old-fashionedBooleanQueryexpansion rewriting and the above points are not relevant then use this to change the rewrite method.- Specified by:
setMultiTermRewriteMethodin interfaceCommonQueryParserConfiguration
-
getMultiTermRewriteMethod
- Specified by:
getMultiTermRewriteMethodin interfaceCommonQueryParserConfiguration- See Also:
-
setLocale
Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.- Specified by:
setLocalein interfaceCommonQueryParserConfiguration
-
getLocale
Returns current locale, allowing access by subclasses.- Specified by:
getLocalein interfaceCommonQueryParserConfiguration
-
setTimeZone
- Specified by:
setTimeZonein interfaceCommonQueryParserConfiguration
-
getTimeZone
- Specified by:
getTimeZonein 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:
setDateResolutionin 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 constructingTermRangeQuerys. 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
TermRangeQuerys.
-
escape
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.
-