Class QueryStringQueryParser

    • Constructor Detail

      • QueryStringQueryParser

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

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

        public QueryStringQueryParser​(QueryShardContext 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​(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

      • setEnablePositionIncrements

        public void setEnablePositionIncrements​(boolean enable)
        Description copied from class: QueryBuilder
        Set to true to enable position increments in result query.

        When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g. a StopFilter increases the position increment of the token that follows an omitted token.

        Default: true.

        Specified by:
        setEnablePositionIncrements in interface CommonQueryParserConfiguration
        Overrides:
        setEnablePositionIncrements in class QueryBuilder
      • setDefaultOperator

        public void setDefaultOperator​(QueryParser.Operator op)
        Description copied from class: QueryParserBase
        Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR) terms without any modifiers are considered optional: for example capital of Hungary is equal to capital OR of OR Hungary.
        In AND_OPERATOR mode terms are considered to be in conjunction: the above mentioned query is parsed as capital AND of AND Hungary
        Overrides:
        setDefaultOperator in class 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​(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​(Analyzer analyzer)
        Parameters:
        analyzer - Force the provided analyzer to be used for all query analysis regardless of the field.
      • setForceQuoteAnalyzer

        public void setForceQuoteAnalyzer​(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)
        Description copied from class: QueryBuilder
        Set to true if phrase queries should be automatically generated for multi terms synonyms. Default: false.
        Overrides:
        setAutoGenerateMultiTermSynonymsPhraseQuery in class QueryBuilder
      • setFuzzyTranspositions

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

        protected Query newFuzzyQuery​(Term term,
                                      float minimumSimilarity,
                                      int prefixLength)
        Description copied from class: QueryParserBase
        Builds a new FuzzyQuery instance
        Overrides:
        newFuzzyQuery in class QueryParserBase
        Parameters:
        term - Term
        minimumSimilarity - minimum similarity
        prefixLength - prefix length
        Returns:
        new FuzzyQuery Instance
      • getPrefixQuery

        protected Query getPrefixQuery​(String field,
                                       String termStr)
                                throws ParseException
        Description copied from class: QueryParserBase
        Factory method for generating a query (similar to QueryParserBase.getWildcardQuery(java.lang.String, java.lang.String)). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.

        Depending on settings, a 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 wild card queries, which may be necessary due to missing analyzer calls.

        Overrides:
        getPrefixQuery in class QueryParserBase
        Parameters:
        field - Name of the field query will use.
        termStr - Term token to use for building term for the query (without trailing '*' character!)
        Returns:
        Resulting Query built for the term
        Throws:
        ParseException - throw in overridden method to disallow
      • getWildcardQuery

        protected Query getWildcardQuery​(String field,
                                         String termStr)
                                  throws ParseException
        Description copied from class: QueryParserBase
        Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

        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.

        Overrides:
        getWildcardQuery in class QueryParserBase
        Parameters:
        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 term
        Returns:
        Resulting Query built for the term
        Throws:
        ParseException - throw in overridden method to disallow
      • getRegexpQuery

        protected Query getRegexpQuery​(String field,
                                       String termStr)
                                throws ParseException
        Description copied from class: QueryParserBase
        Factory method for generating a query. Called when parser parses an input term token that contains a regular expression query.

        Depending on settings, pattern term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with regular expression templates.

        Can be overridden by extending classes, to provide custom handling for regular expression queries, which may be necessary due to missing analyzer calls.

        Overrides:
        getRegexpQuery in class QueryParserBase
        Parameters:
        field - Name of the field query will use.
        termStr - Term token that contains a regular expression
        Returns:
        Resulting Query built for the term
        Throws:
        ParseException - throw in overridden method to disallow
      • getBooleanQuery

        protected Query getBooleanQuery​(List<BooleanClause> clauses)
                                 throws ParseException
        Description copied from class: QueryParserBase
        Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.
        Overrides:
        getBooleanQuery in class QueryParserBase
        Parameters:
        clauses - List that contains BooleanClause instances to join.
        Returns:
        Resulting Query object.
        Throws:
        ParseException - throw in overridden method to disallow