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

public class QueryStringQueryParser extends XQueryParser
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

    Constructors
    Constructor
    Description
    Defaults to all queryable fields extracted from the mapping for query terms
     
    QueryStringQueryParser(SearchExecutionContext context, String defaultField, boolean lenient)
     
     
    QueryStringQueryParser(SearchExecutionContext context, Map<String,Float> fieldsAndWeights, boolean lenient)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    parse(String query)
     
    void
    setAnalyzeWildcard(boolean analyzeWildcard)
     
    void
     
    void
    setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator op)
     
    void
     
    void
    setForceAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
     
    void
    setForceQuoteAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
     
    void
     
    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

      public QueryStringQueryParser(SearchExecutionContext context, String defaultField)
      Parameters:
      context - The query shard context.
      defaultField - The default field for query terms.
    • QueryStringQueryParser

      public QueryStringQueryParser(SearchExecutionContext context, String defaultField, boolean lenient)
      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

      public QueryStringQueryParser(SearchExecutionContext context, Map<String,Float> fieldsAndWeights)
      Parameters:
      context - The query shard context
      fieldsAndWeights - 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

      public QueryStringQueryParser(SearchExecutionContext context, boolean lenient)
      Defaults to all queryable fields extracted from the mapping for query terms
      Parameters:
      context - The query shard context
      lenient - 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 interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
      Overrides:
      setEnablePositionIncrements in class org.apache.lucene.util.QueryBuilder
    • setDefaultOperator

      public void setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator op)
      Overrides:
      setDefaultOperator in class org.apache.lucene.queryparser.classic.QueryParserBase
    • setPhraseSlop

      public void setPhraseSlop(int phraseSlop)
      Specified by:
      setPhraseSlop in interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
      Overrides:
      setPhraseSlop in class org.apache.lucene.queryparser.classic.QueryParserBase
    • setType

      public void setType(MultiMatchQueryBuilder.Type type)
      Parameters:
      type - Sets how multiple fields should be combined to build textual part queries.
    • setFuzziness

      public void setFuzziness(Fuzziness fuzziness)
      Parameters:
      fuzziness - Sets the default Fuzziness for fuzzy query. Defaults to Fuzziness.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 to FuzzyQuery.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

      public void setQuoteFieldSuffix(String quoteFieldSuffix)
      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

      public void setTimeZone(ZoneId timeZone)
      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 class org.apache.lucene.util.QueryBuilder
    • setFuzzyTranspositions

      public void setFuzzyTranspositions(boolean fuzzyTranspositions)
      Parameters:
      fuzzyTranspositions - Sets whether transpositions are supported in fuzzy queries. Defaults to FuzzyQuery.defaultTranspositions.
    • newMatchAllDocsQuery

      protected org.apache.lucene.search.Query newMatchAllDocsQuery()
      Overrides:
      newMatchAllDocsQuery in class org.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 class org.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 class org.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 class org.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 class XQueryParser
      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 class org.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 class org.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 class org.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 class org.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 class org.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 class org.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 class org.apache.lucene.queryparser.classic.QueryParserBase
      Throws:
      org.apache.lucene.queryparser.classic.ParseException