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
The
ExtendableQueryParser 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. The ExtendableQueryParser allows to encode extension
keys into the field symbol associated with a registered instance of
ParserExtension. A customizable separation character separates the
extension key from the actual field symbol. The ExtendableQueryParser
splits (@see Extensions.splitExtensionField(String, String)) the
extension key from the field symbol and tries to resolve the associated
ParserExtension. 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 class QueryParser. Otherwise,
if the key is associated with a ParserExtension instance, the parser
builds an instance of ExtensionQuery to be processed by
ParserExtension.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 in Extensions.
Customized extension schemes should be implemented by sub-classing
Extensions.
For details about the default encoding scheme see Extensions.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser
QueryParser.OperatorNested classes/interfaces inherited from class org.apache.lucene.util.QueryBuilder
QueryBuilder.TermAndBoost -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ExtensionsDefault empty extensions instanceprivate final Stringprivate final ExtensionsFields inherited from class org.apache.lucene.queryparser.classic.QueryParser
DEFAULT_SPLIT_ON_WHITESPACE, jj_nt, token, token_sourceFields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
AND_OPERATOR, field, OR_OPERATORFields inherited from class org.apache.lucene.util.QueryBuilder
analyzer, autoGenerateMultiTermSynonymsPhraseQuery, enableGraphQueries, enablePositionIncrementsFields 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
ConstructorsConstructorDescriptionCreates a newExtendableQueryParserinstanceExtendableQueryParser(String f, Analyzer a, Extensions ext) Creates a newExtendableQueryParserinstance -
Method Summary
Modifier and TypeMethodDescriptioncharReturns the extension field delimiter character.protected QuerygetFieldQuery(String field, String queryText, boolean quoted) Methods inherited from class org.apache.lucene.queryparser.classic.QueryParser
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getSplitOnWhitespace, getToken, Modifiers, MultiTerm, Query, ReInit, ReInit, setAutoGeneratePhraseQueries, setSplitOnWhitespace, Term, TopLevelQueryMethods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
addClause, addMultiTermClauses, escape, getAllowLeadingWildcard, getAutoGeneratePhraseQueries, getBooleanQuery, getDateResolution, getDefaultOperator, getField, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, getLocale, getMaxDeterminizedStates, getMultiTermRewriteMethod, getPhraseSlop, getPrefixQuery, getRangeQuery, getRegexpQuery, getTimeZone, getWildcardQuery, init, newBooleanClause, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newPrefixQuery, newRangeQuery, newRegexpQuery, newWildcardQuery, parse, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setMaxDeterminizedStates, setMultiTermRewriteMethod, setPhraseSlop, setTimeZoneMethods inherited from class org.apache.lucene.util.QueryBuilder
add, analyzeBoolean, analyzeGraphBoolean, analyzeGraphPhrase, analyzeMultiBoolean, analyzeMultiPhrase, analyzePhrase, analyzeTerm, createBooleanQuery, createBooleanQuery, createFieldQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, createSpanQuery, getAnalyzer, getAutoGenerateMultiTermSynonymsPhraseQuery, getEnableGraphQueries, getEnablePositionIncrements, newBooleanQuery, newGraphSynonymQuery, newMultiPhraseQueryBuilder, newSynonymQuery, newTermQuery, setAnalyzer, setAutoGenerateMultiTermSynonymsPhraseQuery, setEnableGraphQueries, setEnablePositionIncrementsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
-
Field Details
-
defaultField
-
extensions
-
DEFAULT_EXTENSION
Default empty extensions instance
-
-
Constructor Details
-
ExtendableQueryParser
Creates a newExtendableQueryParserinstance- Parameters:
f- the default query fielda- the analyzer used to find terms in a query string
-
ExtendableQueryParser
Creates a newExtendableQueryParserinstance- Parameters:
f- the default query fielda- the analyzer used to find terms in a query stringext- the query parser extensions
-
-
Method Details
-
getExtensionFieldDelimiter
public char getExtensionFieldDelimiter()Returns the extension field delimiter character.- Returns:
- the extension field delimiter character.
-
getFieldQuery
- Overrides:
getFieldQueryin classQueryParserBase- Throws:
ParseException- throw in overridden method to disallow
-