public class ComplexPhraseQueryParser extends QueryParser
Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects
This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status
QueryParser.Operator
QueryParserBase.MethodRemovedUseAnother
jj_nt, token, token_source
AND_OPERATOR, field, OR_OPERATOR
_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 and Description |
---|
ComplexPhraseQueryParser(String f,
Analyzer a) |
Modifier and Type | Method and Description |
---|---|
protected Query |
getFieldQuery(String field,
String queryText,
int slop)
Base implementation delegates to
QueryParserBase.getFieldQuery(String,String,boolean) . |
protected Query |
getFuzzyQuery(String field,
String termStr,
float minSimilarity)
Factory method for generating a query (similar to
QueryParserBase.getWildcardQuery(java.lang.String, java.lang.String) ). |
protected Query |
getRangeQuery(String field,
String part1,
String part2,
boolean startInclusive,
boolean endInclusive) |
protected Query |
getWildcardQuery(String field,
String termStr)
Factory method for generating a query.
|
protected Query |
newRangeQuery(String field,
String part1,
String part2,
boolean startInclusive,
boolean endInclusive)
Builds a new
TermRangeQuery instance |
protected Query |
newTermQuery(Term term) |
Query |
parse(String query)
Parses a query string, returning a
Query . |
void |
setInOrder(boolean inOrder)
When
inOrder is true, the search terms must
exists in the documents as the same order as in query. |
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getToken, Modifiers, Query, ReInit, ReInit, Term, TopLevelQuery
addClause, analyzeMultitermTerm, escape, getAllowLeadingWildcard, getAnalyzeRangeTerms, getAutoGeneratePhraseQueries, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getField, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMaxDeterminizedStates, getMultiTermRewriteMethod, getPhraseSlop, getPrefixQuery, getRegexpQuery, getTimeZone, init, newBooleanClause, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newPrefixQuery, newRegexpQuery, newWildcardQuery, setAllowLeadingWildcard, setAnalyzeRangeTerms, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMaxDeterminizedStates, setMultiTermRewriteMethod, setPhraseSlop, setTimeZone
createBooleanQuery, createBooleanQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, newBooleanQuery, newMultiPhraseQuery, setAnalyzer, setEnablePositionIncrements
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
public void setInOrder(boolean inOrder)
inOrder
is true, the search terms must
exists in the documents as the same order as in query.inOrder
- parameter to choose between ordered or un-ordered proximity searchprotected Query getFieldQuery(String field, String queryText, int slop)
QueryParserBase
QueryParserBase.getFieldQuery(String,String,boolean)
.
This method may be overridden, for example, to return
a SpanNearQuery instead of a PhraseQuery.getFieldQuery
in class QueryParserBase
public Query parse(String query) throws ParseException
QueryParserBase
Query
.parse
in class QueryParserBase
query
- the query string to be parsed.ParseException
- if the parsing failsprotected Query newTermQuery(Term term)
newTermQuery
in class QueryBuilder
protected Query getWildcardQuery(String field, String termStr) throws ParseException
QueryParserBase
Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.
Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.
getWildcardQuery
in class QueryParserBase
field
- Name of the field query will use.termStr
- Term token that contains one or more wild card
characters (? or *), but is not simple prefix termQuery
built for the termParseException
- throw in overridden method to disallowprotected Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws ParseException
getRangeQuery
in class QueryParserBase
ParseException
protected Query newRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)
QueryParserBase
TermRangeQuery
instancenewRangeQuery
in class QueryParserBase
field
- Fieldpart1
- minpart2
- maxstartInclusive
- true if the start of the range is inclusiveendInclusive
- true if the end of the range is inclusiveTermRangeQuery
instanceprotected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
QueryParserBase
QueryParserBase.getWildcardQuery(java.lang.String, java.lang.String)
). Called when parser parses
an input term token that has the fuzzy suffix (~) appended.getFuzzyQuery
in class QueryParserBase
field
- Name of the field query will use.termStr
- Term token to use for building term for the queryQuery
built for the termParseException
- throw in overridden method to disallowCopyright © 2000-2015 Apache Software Foundation. All Rights Reserved.