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 Classes Modifier and Type Class Description static classQueryParserBase.MethodRemovedUseAnotherDo not catch this exception in your code, it means you are using methods that you should no longer use.
-
Field Summary
Fields Modifier and Type Field Description static QueryParser.OperatorAND_OPERATORAlternative form of QueryParser.Operator.ANDstatic QueryParser.OperatorOR_OPERATORAlternative form of QueryParser.Operator.OR
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringescape(java.lang.String s)Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.booleangetAllowLeadingWildcard()booleangetAnalyzeRangeTerms()booleangetAutoGeneratePhraseQueries()DateTools.ResolutiongetDateResolution(java.lang.String fieldName)Returns the date resolution that is used by RangeQueries for the given field.QueryParser.OperatorgetDefaultOperator()Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.java.lang.StringgetField()floatgetFuzzyMinSim()Get the minimal similarity for fuzzy queries.intgetFuzzyPrefixLength()Get the prefix length for fuzzy queries.java.util.LocalegetLocale()Returns current locale, allowing access by subclasses.booleangetLowercaseExpandedTerms()MultiTermQuery.RewriteMethodgetMultiTermRewriteMethod()intgetPhraseSlop()Gets the default slop for phrases.java.util.TimeZonegetTimeZone()voidinit(Version matchVersion, java.lang.String f, Analyzer a)Initializes a query parser.Queryparse(java.lang.String query)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.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(java.lang.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.voidsetDefaultOperator(QueryParser.Operator op)Sets 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.voidsetLocale(java.util.Locale locale)Set 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.voidsetMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULTwhen creating aPrefixQuery,WildcardQueryorTermRangeQuery.voidsetPhraseSlop(int phraseSlop)Sets the default slop for phrases.voidsetTimeZone(java.util.TimeZone timeZone)abstract QueryTopLevelQuery(java.lang.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 Detail
-
AND_OPERATOR
public static final QueryParser.Operator AND_OPERATOR
Alternative form of QueryParser.Operator.AND
-
OR_OPERATOR
public static final QueryParser.Operator OR_OPERATOR
Alternative form of QueryParser.Operator.OR
-
-
Method Detail
-
init
public void init(Version matchVersion, java.lang.String f, Analyzer a)
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
public abstract void ReInit(CharStream stream)
-
TopLevelQuery
public abstract Query TopLevelQuery(java.lang.String field) throws ParseException
- Throws:
ParseException
-
parse
public Query parse(java.lang.String query) throws ParseException
Parses a query string, returning aQuery.- Parameters:
query- the query string to be parsed.- Throws:
ParseException- if the parsing fails
-
getField
public java.lang.String getField()
- Returns:
- Returns the default field.
-
getAutoGeneratePhraseQueries
public final boolean getAutoGeneratePhraseQueries()
- See Also:
setAutoGeneratePhraseQueries(boolean)
-
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:
setAllowLeadingWildcard(boolean)
-
setDefaultOperator
public void setDefaultOperator(QueryParser.Operator op)
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
public QueryParser.Operator 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:
setLowercaseExpandedTerms(boolean)
-
setMultiTermRewriteMethod
public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)
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
public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod()
- Specified by:
getMultiTermRewriteMethodin interfaceCommonQueryParserConfiguration- See Also:
setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod)
-
setLocale
public void setLocale(java.util.Locale locale)
Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.- Specified by:
setLocalein interfaceCommonQueryParserConfiguration
-
getLocale
public java.util.Locale getLocale()
Returns current locale, allowing access by subclasses.- Specified by:
getLocalein interfaceCommonQueryParserConfiguration
-
setTimeZone
public void setTimeZone(java.util.TimeZone timeZone)
- Specified by:
setTimeZonein interfaceCommonQueryParserConfiguration
-
getTimeZone
public java.util.TimeZone getTimeZone()
- Specified by:
getTimeZonein interfaceCommonQueryParserConfiguration
-
setDateResolution
public 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 withsetDateResolution(String, org.apache.lucene.document.DateTools.Resolution).- Specified by:
setDateResolutionin interfaceCommonQueryParserConfiguration- Parameters:
dateResolution- the default date resolution to set
-
setDateResolution
public void setDateResolution(java.lang.String fieldName, DateTools.Resolution dateResolution)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
public DateTools.Resolution getDateResolution(java.lang.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.
-
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
public static java.lang.String escape(java.lang.String s)
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.
-
-