Class 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 MultiMatchQuery 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
    • 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
    • Method Summary

      Modifier and Type Method Description
      protected org.apache.lucene.search.Query getBooleanQuery​(java.util.List<org.apache.lucene.search.BooleanClause> clauses)  
      org.apache.lucene.search.Query getFieldQuery​(java.lang.String field, java.lang.String queryText, boolean quoted)  
      protected org.apache.lucene.search.Query getFieldQuery​(java.lang.String field, java.lang.String queryText, int slop)  
      protected org.apache.lucene.search.Query getFuzzyQuery​(java.lang.String field, java.lang.String termStr, float minSimilarity)  
      protected org.apache.lucene.search.Query getPrefixQuery​(java.lang.String field, java.lang.String termStr)  
      protected org.apache.lucene.search.Query getRangeQuery​(java.lang.String field, java.lang.String part1, java.lang.String part2, boolean startInclusive, boolean endInclusive)  
      protected org.apache.lucene.search.Query getRegexpQuery​(java.lang.String field, java.lang.String termStr)  
      protected org.apache.lucene.search.Query getWildcardQuery​(java.lang.String field, java.lang.String termStr)  
      protected org.apache.lucene.search.Query handleBareFuzzy​(java.lang.String field, org.apache.lucene.queryparser.classic.Token fuzzySlop, java.lang.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 newMatchAllDocsQuery()  
      protected org.apache.lucene.search.Query newTermQuery​(org.apache.lucene.index.Term term)  
      org.apache.lucene.search.Query parse​(java.lang.String query)  
      void setAnalyzeWildcard​(boolean analyzeWildcard)  
      void setAutoGenerateMultiTermSynonymsPhraseQuery​(boolean enable)  
      void setDefaultOperator​(org.apache.lucene.queryparser.classic.QueryParser.Operator op)  
      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​(java.lang.String quoteFieldSuffix)  
      void setTimeZone​(org.joda.time.DateTimeZone timeZone)  
      void setType​(MultiMatchQueryBuilder.Type type)  
      • 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, setAnalyzer, setEnableGraphQueries, setEnablePositionIncrements
      • 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, setEnablePositionIncrements
    • Constructor Detail

      • QueryStringQueryParser

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

        public QueryStringQueryParser​(QueryShardContext context,
                                      java.lang.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​(QueryShardContext context,
                                      java.util.Map<java.lang.String,​java.lang.Float> fieldsAndWeights)
        Parameters:
        context - The query shard context
        fieldsAndWeights - The default fields and weights expansion for query terms
      • QueryStringQueryParser

        public QueryStringQueryParser​(QueryShardContext context,
                                      java.util.Map<java.lang.String,​java.lang.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​(QueryShardContext context,
                                      boolean lenient)
        Defaults to all queryiable 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 Detail

      • 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​(java.lang.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​(org.joda.time.DateTimeZone 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.
      • newTermQuery

        protected org.apache.lucene.search.Query newTermQuery​(org.apache.lucene.index.Term term)
        Overrides:
        newTermQuery in class org.apache.lucene.util.QueryBuilder
      • 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​(java.lang.String field,
                                                            java.lang.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​(java.lang.String field,
                                                               java.lang.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​(java.lang.String field,
                                                               java.lang.String part1,
                                                               java.lang.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​(java.lang.String field,
                                                                 org.apache.lucene.queryparser.classic.Token fuzzySlop,
                                                                 java.lang.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​(java.lang.String field,
                                                               java.lang.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​(java.lang.String field,
                                                                java.lang.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​(java.lang.String field,
                                                                  java.lang.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​(java.lang.String field,
                                                                java.lang.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​(java.util.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​(java.lang.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