Class ExtendableQueryParser
- java.lang.Object
-
- org.apache.lucene.util.QueryBuilder
-
- org.apache.lucene.queryparser.classic.QueryParserBase
-
- org.apache.lucene.queryparser.classic.QueryParser
-
- org.apache.lucene.queryparser.ext.ExtendableQueryParser
-
- All Implemented Interfaces:
QueryParserConstants
,CommonQueryParserConfiguration
public class ExtendableQueryParser extends QueryParser
TheExtendableQueryParser
enables arbitrary query parser extension based on a customizable field naming scheme. The lucene query syntax allows implicit and explicit field definitions as query prefix followed by a colon (':') character. TheExtendableQueryParser
allows to encode extension keys into the field symbol associated with a registered instance ofParserExtension
. A customizable separation character separates the extension key from the actual field symbol. TheExtendableQueryParser
splits (@seeExtensions.splitExtensionField(String, String)
) the extension key from the field symbol and tries to resolve the associatedParserExtension
. If the parser can't resolve the key or the field token does not contain a separation character,ExtendableQueryParser
yields the same behavior as its super classQueryParser
. Otherwise, if the key is associated with aParserExtension
instance, the parser builds an instance ofExtensionQuery
to be processed byParserExtension.parse(ExtensionQuery)
.If a extension field does not contain a field part the default field for the query will be used.To guarantee that an extension field is processed with its associated extension, the extension query part must escape any special characters like '*' or '['. If the extension query contains any whitespace characters, the extension query part must be enclosed in quotes. Example ('_' used as separation character):
title_customExt:"Apache Lucene\?" OR content_customExt:prefix\*
Search on the default field:_customExt:"Apache Lucene\?" OR _customExt:prefix\*
The
ExtendableQueryParser
itself does not implement the logic how field and extension key are separated or ordered. All logic regarding the extension key and field symbol parsing is located inExtensions
. Customized extension schemes should be implemented by sub-classingExtensions
.For details about the default encoding scheme see
Extensions
.- See Also:
Extensions
,ParserExtension
,ExtensionQuery
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser
QueryParser.Operator
-
Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
QueryParserBase.MethodRemovedUseAnother
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.queryparser.classic.QueryParser
jj_nt, token, token_source
-
Fields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
AND_OPERATOR, OR_OPERATOR
-
Fields inherited from interface org.apache.lucene.queryparser.classic.QueryParserConstants
_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, BAREOPER, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, Range, RANGE_GOOP, RANGE_QUOTED, RANGE_TO, RANGEEX_END, RANGEEX_START, RANGEIN_END, RANGEIN_START, REGEXPTERM, RPAREN, STAR, TERM, tokenImage, WILDTERM
-
-
Constructor Summary
Constructors Constructor Description ExtendableQueryParser(Version matchVersion, java.lang.String f, Analyzer a)
Creates a newExtendableQueryParser
instanceExtendableQueryParser(Version matchVersion, java.lang.String f, Analyzer a, Extensions ext)
Creates a newExtendableQueryParser
instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description char
getExtensionFieldDelimiter()
Returns the extension field delimiter character.-
Methods inherited from class org.apache.lucene.queryparser.classic.QueryParser
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getToken, Modifiers, Query, ReInit, ReInit, Term, TopLevelQuery
-
Methods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
escape, getAllowLeadingWildcard, getAnalyzeRangeTerms, getAutoGeneratePhraseQueries, getDateResolution, getDefaultOperator, getField, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getPhraseSlop, getTimeZone, init, parse, setAllowLeadingWildcard, setAnalyzeRangeTerms, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setTimeZone
-
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
-
-
-
-
Constructor Detail
-
ExtendableQueryParser
public ExtendableQueryParser(Version matchVersion, java.lang.String f, Analyzer a)
Creates a newExtendableQueryParser
instance- Parameters:
matchVersion
- the lucene version to use.f
- the default query fielda
- the analyzer used to find terms in a query string
-
ExtendableQueryParser
public ExtendableQueryParser(Version matchVersion, java.lang.String f, Analyzer a, Extensions ext)
Creates a newExtendableQueryParser
instance- Parameters:
matchVersion
- the lucene version to use.f
- the default query fielda
- the analyzer used to find terms in a query stringext
- the query parser extensions
-
-