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.OperatorAND_OPERATOR, jj_nt, OR_OPERATOR, token, token_source_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RangeEx, RANGEEX_END, RANGEEX_GOOP, RANGEEX_QUOTED, RANGEEX_START, RANGEEX_TO, RangeIn, RANGEIN_END, RANGEIN_GOOP, RANGEIN_QUOTED, RANGEIN_START, RANGEIN_TO, RPAREN, STAR, TERM, tokenImage, WILDTERM| Constructor and Description |
|---|
ComplexPhraseQueryParser(Version matchVersion,
String f,
Analyzer a) |
| Modifier and Type | Method and Description |
|---|---|
protected Query |
getFieldQuery(String field,
String queryText,
int slop)
Base implementation delegates to
QueryParser.getFieldQuery(String,String,boolean). |
protected Query |
getFuzzyQuery(String field,
String termStr,
float minSimilarity)
Factory method for generating a query (similar to
QueryParser.getWildcardQuery(java.lang.String, java.lang.String)). |
protected Query |
getRangeQuery(String field,
String part1,
String part2,
boolean inclusive) |
protected Query |
getWildcardQuery(String field,
String termStr)
Factory method for generating a query.
|
protected Query |
newRangeQuery(String field,
String part1,
String part2,
boolean inclusive)
Builds a new TermRangeQuery instance
|
protected Query |
newTermQuery(Term term)
Builds a new TermQuery instance
|
Query |
parse(String query)
Parses a query string, returning a
Query. |
addClause, Clause, Conjunction, disable_tracing, enable_tracing, escape, generateParseException, getAllowLeadingWildcard, getAnalyzer, getAutoGeneratePhraseQueries, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFieldQuery, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getNextToken, getPhraseSlop, getPrefixQuery, getRangeCollator, getToken, main, Modifiers, newBooleanClause, newBooleanQuery, newFuzzyQuery, newMatchAllDocsQuery, newMultiPhraseQuery, newPhraseQuery, newPrefixQuery, newWildcardQuery, Query, ReInit, ReInit, setAllowLeadingWildcard, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setRangeCollator, Term, TopLevelQueryprotected Query getFieldQuery(String field, String queryText, int slop)
QueryParserQueryParser.getFieldQuery(String,String,boolean).
This method may be overridden, for example, to return
a SpanNearQuery instead of a PhraseQuery.getFieldQuery in class QueryParserpublic Query parse(String query) throws ParseException
QueryParserQuery.parse in class QueryParserquery - the query string to be parsed.ParseException - if the parsing failsprotected Query newTermQuery(Term term)
QueryParsernewTermQuery in class QueryParserterm - termprotected Query getWildcardQuery(String field, String termStr) throws ParseException
QueryParserDepending 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 QueryParserfield - 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 inclusive) throws ParseException
getRangeQuery in class QueryParserParseException - throw in overridden method to disallowprotected Query newRangeQuery(String field, String part1, String part2, boolean inclusive)
QueryParsernewRangeQuery in class QueryParserfield - Fieldpart1 - minpart2 - maxinclusive - true if range is inclusiveprotected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
QueryParserQueryParser.getWildcardQuery(java.lang.String, java.lang.String)). Called when parser parses
an input term token that has the fuzzy suffix (~) appended.getFuzzyQuery in class QueryParserfield - 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 disallow