Class QueryParserBase

    • Field Detail


        public static final QueryParser.Operator AND_OPERATOR
        Alternative form of QueryParser.Operator.AND

        public static final QueryParser.Operator OR_OPERATOR
        Alternative form of QueryParser.Operator.OR
    • Method Detail

      • init

        public void init​(Version matchVersion,
                         java.lang.String f,
                         Analyzer a)
        Initializes a query parser. Called by the QueryParser constructor
        matchVersion - Lucene version to match. See here.
        f - the default field for query terms.
        a - used to find terms in the query text.
      • ReInit

        public abstract void ReInit​(CharStream stream)
      • parse

        public Query parse​(java.lang.String query)
                    throws ParseException
        Parses a query string, returning a Query.
        query - the query string to be parsed.
        ParseException - if the parsing fails
      • getField

        public java.lang.String getField()
        Returns the default field.
      • setAutoGeneratePhraseQueries

        public final void setAutoGeneratePhraseQueries​(boolean value)
        Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text. NOTE: this behavior may not be suitable for all languages.

        Set to false if phrase queries should only be generated when surrounded by double quotes.

      • setFuzzyPrefixLength

        public void setFuzzyPrefixLength​(int fuzzyPrefixLength)
        Set the prefix length for fuzzy queries. Default is 0.
        Specified by:
        setFuzzyPrefixLength in interface CommonQueryParserConfiguration
        fuzzyPrefixLength - The fuzzyPrefixLength to set.
      • setPhraseSlop

        public void setPhraseSlop​(int phraseSlop)
        Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
        Specified by:
        setPhraseSlop in interface CommonQueryParserConfiguration
      • setAllowLeadingWildcard

        public void setAllowLeadingWildcard​(boolean allowLeadingWildcard)
        Set to true to allow leading wildcard characters.

        When set, * or ? are allowed as the first character of a PrefixQuery and WildcardQuery. Note that this can produce very slow queries on big indexes.

        Default: false.

        Specified by:
        setAllowLeadingWildcard in interface CommonQueryParserConfiguration
      • setDefaultOperator

        public void setDefaultOperator​(QueryParser.Operator op)
        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
      • getDefaultOperator

        public QueryParser.Operator getDefaultOperator()
        Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
      • setLowercaseExpandedTerms

        public void setLowercaseExpandedTerms​(boolean lowercaseExpandedTerms)
        Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.
        Specified by:
        setLowercaseExpandedTerms in interface CommonQueryParserConfiguration
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.
        Specified by:
        setLocale in interface CommonQueryParserConfiguration
      • setDateResolution

        public void setDateResolution​(java.lang.String fieldName,
                                      DateTools.Resolution dateResolution)
        Sets the date resolution used by RangeQueries for a specific field.
        fieldName - field for which the date resolution is to be set
        dateResolution - date resolution to set
      • getDateResolution

        public DateTools.Resolution getDateResolution​(java.lang.String fieldName)
        Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.
      • setAnalyzeRangeTerms

        public void setAnalyzeRangeTerms​(boolean analyzeRangeTerms)
        Set whether or not to analyze range terms when constructing TermRangeQuerys. For example, setting this to true can enable analyzing terms into collation keys for locale-sensitive TermRangeQuery.
        analyzeRangeTerms - whether or not terms should be analyzed for RangeQuerys
      • getAnalyzeRangeTerms

        public boolean getAnalyzeRangeTerms()
        whether or not to analyze range terms when constructing TermRangeQuerys.
      • escape

        public static java.lang.String escape​(java.lang.String s)
        Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.