Package org.elasticsearch.index.search
Class QueryStringQueryParser
java.lang.Object
org.apache.lucene.util.QueryBuilder
org.apache.lucene.queryparser.classic.QueryParserBase
org.apache.lucene.queryparser.classic.QueryParser
org.apache.lucene.queryparser.classic.XQueryParser
org.elasticsearch.index.search.QueryStringQueryParser
- All Implemented Interfaces:
org.apache.lucene.queryparser.classic.QueryParserConstants
,org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
A
XQueryParser
that uses the MapperService
in order to build smarter
queries based on the mapping information.
This class uses MultiMatchQueryParser
to build the text query around operators and XQueryParser
to assemble the result logically.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser
org.apache.lucene.queryparser.classic.QueryParser.Operator
Nested classes/interfaces inherited from class org.apache.lucene.util.QueryBuilder
org.apache.lucene.util.QueryBuilder.TermAndBoost
-
Field Summary
Fields inherited from class org.apache.lucene.queryparser.classic.QueryParser
DEFAULT_SPLIT_ON_WHITESPACE, jj_nt, token, token_source
Fields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
AND_OPERATOR, field, OR_OPERATOR
Fields inherited from class org.apache.lucene.util.QueryBuilder
analyzer, autoGenerateMultiTermSynonymsPhraseQuery, enableGraphQueries, enablePositionIncrements
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
ConstructorDescriptionQueryStringQueryParser(SearchExecutionContext context, boolean lenient)
Defaults to all queryable fields extracted from the mapping for query termsQueryStringQueryParser(SearchExecutionContext context, String defaultField)
QueryStringQueryParser(SearchExecutionContext context, String defaultField, boolean lenient)
QueryStringQueryParser(SearchExecutionContext context, Map<String,Float> fieldsAndWeights)
QueryStringQueryParser(SearchExecutionContext context, Map<String,Float> fieldsAndWeights, boolean lenient)
-
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.lucene.search.Query
getBooleanQuery(List<org.apache.lucene.search.BooleanClause> clauses)
org.apache.lucene.search.Query
getFieldQuery(String field, String queryText, boolean quoted)
protected org.apache.lucene.search.Query
getFieldQuery(String field, String queryText, int slop)
protected org.apache.lucene.search.Query
getFuzzyQuery(String field, String termStr, float minSimilarity)
protected org.apache.lucene.search.Query
getPrefixQuery(String field, String termStr)
protected org.apache.lucene.search.Query
getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)
protected org.apache.lucene.search.Query
getRegexpQuery(String field, String termStr)
protected org.apache.lucene.search.Query
getWildcardQuery(String field, String termStr)
protected org.apache.lucene.search.Query
handleBareFuzzy(String field, org.apache.lucene.queryparser.classic.Token fuzzySlop, String termImage)
protected org.apache.lucene.search.Query
newFuzzyQuery(org.apache.lucene.index.Term term, float minimumSimilarity, int prefixLength)
protected org.apache.lucene.search.Query
org.apache.lucene.search.Query
void
setAnalyzeWildcard(boolean analyzeWildcard)
void
setAutoGenerateMultiTermSynonymsPhraseQuery(boolean enable)
void
setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator op)
void
setEnablePositionIncrements(boolean enable)
void
setForceAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
void
setForceQuoteAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
void
setFuzziness(Fuzziness fuzziness)
void
setFuzzyMaxExpansions(int fuzzyMaxExpansions)
void
setFuzzyRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod fuzzyRewriteMethod)
void
setFuzzyTranspositions(boolean fuzzyTranspositions)
void
setGroupTieBreaker(float groupTieBreaker)
void
setPhraseSlop(int phraseSlop)
void
setQuoteFieldSuffix(String quoteFieldSuffix)
void
setTimeZone(ZoneId timeZone)
void
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, TopLevelQuery
Methods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
addClause, addMultiTermClauses, escape, getAllowLeadingWildcard, getAutoGeneratePhraseQueries, getDateResolution, getDefaultOperator, getField, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getMaxDeterminizedStates, getMultiTermRewriteMethod, getPhraseSlop, getTimeZone, init, newBooleanClause, newFieldQuery, newPrefixQuery, newRangeQuery, newRegexpQuery, newWildcardQuery, setAllowLeadingWildcard, setDateResolution, setDateResolution, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setMaxDeterminizedStates, setMultiTermRewriteMethod, setTimeZone
Methods 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, setEnableGraphQueries
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
getAnalyzer, getEnablePositionIncrements
-
Constructor Details
-
QueryStringQueryParser
- Parameters:
context
- The query shard context.defaultField
- The default field for query terms.
-
QueryStringQueryParser
- Parameters:
context
- The query shard context.defaultField
- The default field for query terms.lenient
- If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored.
-
QueryStringQueryParser
- Parameters:
context
- The query shard contextfieldsAndWeights
- The default fields and weights expansion for query terms
-
QueryStringQueryParser
public QueryStringQueryParser(SearchExecutionContext context, Map<String,Float> fieldsAndWeights, boolean lenient)- Parameters:
context
- The query shard context.fieldsAndWeights
- The default fields and weights expansion for query terms.lenient
- If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored.
-
QueryStringQueryParser
Defaults to all queryable fields extracted from the mapping for query terms- Parameters:
context
- The query shard contextlenient
- If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored.
-
-
Method Details
-
setEnablePositionIncrements
public void setEnablePositionIncrements(boolean enable)- Specified by:
setEnablePositionIncrements
in interfaceorg.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
- Overrides:
setEnablePositionIncrements
in classorg.apache.lucene.util.QueryBuilder
-
setDefaultOperator
public void setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator op)- Overrides:
setDefaultOperator
in classorg.apache.lucene.queryparser.classic.QueryParserBase
-
setPhraseSlop
public void setPhraseSlop(int phraseSlop)- Specified by:
setPhraseSlop
in interfaceorg.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
- Overrides:
setPhraseSlop
in classorg.apache.lucene.queryparser.classic.QueryParserBase
-
setType
- Parameters:
type
- Sets how multiple fields should be combined to build textual part queries.
-
setFuzziness
- Parameters:
fuzziness
- Sets the defaultFuzziness
for fuzzy query. Defaults toFuzziness.AUTO
.
-
setFuzzyRewriteMethod
public void setFuzzyRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod fuzzyRewriteMethod)- Parameters:
fuzzyRewriteMethod
- Sets the default rewrite method for fuzzy query.
-
setFuzzyMaxExpansions
public void setFuzzyMaxExpansions(int fuzzyMaxExpansions)- Parameters:
fuzzyMaxExpansions
- Sets the maximum number of expansions allowed in a fuzzy query. Defaults toFuzzyQuery.defaultMaxExpansions
.
-
setForceAnalyzer
public void setForceAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)- Parameters:
analyzer
- Force the provided analyzer to be used for all query analysis regardless of the field.
-
setForceQuoteAnalyzer
public void setForceQuoteAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)- Parameters:
analyzer
- Force the provided analyzer to be used for all phrase query analysis regardless of the field.
-
setQuoteFieldSuffix
- Parameters:
quoteFieldSuffix
- The suffix to append to fields for quoted parts of the query string.
-
setAnalyzeWildcard
public void setAnalyzeWildcard(boolean analyzeWildcard)- Parameters:
analyzeWildcard
- If true, the wildcard operator analyzes the term to build a wildcard query. Otherwise the query terms are only normalized.
-
setTimeZone
- Parameters:
timeZone
- Time Zone to be applied to any range query related to dates.
-
setGroupTieBreaker
public void setGroupTieBreaker(float groupTieBreaker)- Parameters:
groupTieBreaker
- The tie breaker to apply when multiple fields are used.
-
setAutoGenerateMultiTermSynonymsPhraseQuery
public void setAutoGenerateMultiTermSynonymsPhraseQuery(boolean enable)- Overrides:
setAutoGenerateMultiTermSynonymsPhraseQuery
in classorg.apache.lucene.util.QueryBuilder
-
setFuzzyTranspositions
public void setFuzzyTranspositions(boolean fuzzyTranspositions)- Parameters:
fuzzyTranspositions
- Sets whether transpositions are supported in fuzzy queries. Defaults toFuzzyQuery.defaultTranspositions
.
-
newMatchAllDocsQuery
protected org.apache.lucene.search.Query newMatchAllDocsQuery()- Overrides:
newMatchAllDocsQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
-
getFieldQuery
public org.apache.lucene.search.Query getFieldQuery(String field, String queryText, boolean quoted) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getFieldQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getFieldQuery
protected org.apache.lucene.search.Query getFieldQuery(String field, String queryText, int slop) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getFieldQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getRangeQuery
protected org.apache.lucene.search.Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getRangeQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
handleBareFuzzy
protected org.apache.lucene.search.Query handleBareFuzzy(String field, org.apache.lucene.queryparser.classic.Token fuzzySlop, String termImage) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
handleBareFuzzy
in classXQueryParser
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getFuzzyQuery
protected org.apache.lucene.search.Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getFuzzyQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
newFuzzyQuery
protected org.apache.lucene.search.Query newFuzzyQuery(org.apache.lucene.index.Term term, float minimumSimilarity, int prefixLength)- Overrides:
newFuzzyQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
-
getPrefixQuery
protected org.apache.lucene.search.Query getPrefixQuery(String field, String termStr) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getPrefixQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getWildcardQuery
protected org.apache.lucene.search.Query getWildcardQuery(String field, String termStr) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getWildcardQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getRegexpQuery
protected org.apache.lucene.search.Query getRegexpQuery(String field, String termStr) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getRegexpQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getBooleanQuery
protected org.apache.lucene.search.Query getBooleanQuery(List<org.apache.lucene.search.BooleanClause> clauses) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
getBooleanQuery
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
parse
public org.apache.lucene.search.Query parse(String query) throws org.apache.lucene.queryparser.classic.ParseException- Overrides:
parse
in classorg.apache.lucene.queryparser.classic.QueryParserBase
- Throws:
org.apache.lucene.queryparser.classic.ParseException
-