Class SolrQueryParserBase

  • Direct Known Subclasses:

    public abstract class SolrQueryParserBase
    extends org.apache.lucene.util.QueryBuilder
    This class is overridden by QueryParser in QueryParser.jj and acts to separate the majority of the Java code from the .jj grammar file.
    • Constructor Detail

      • SolrQueryParserBase

        protected SolrQueryParserBase()
    • Method Detail

      • ReInit

        public abstract void ReInit​(org.apache.lucene.queryparser.charstream.CharStream stream)
      • init

        public void init​(String defaultField,
                         QParser parser)
      • parse

        public parse​(String query)
                                             throws SyntaxError
        Parses a query string, returning a Query.
        query - the query string to be parsed.
      • getDefaultField

        public String getDefaultField()
        Returns the default field.
      • getField

        public String getField​(String fieldName)
        Handles the default field if null is passed
      • getExplicitField

        public String getExplicitField()
        For a fielded query, returns the actual field specified (i.e. null if default is being used) myfield:A or myfield:(A B C) will both return "myfield"
      • 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.

      • getFuzzyMinSim

        public float getFuzzyMinSim()
        Get the minimal similarity for fuzzy queries.
      • setFuzzyMinSim

        public void setFuzzyMinSim​(float fuzzyMinSim)
        Set the minimum similarity for fuzzy queries. Default is 2f.
      • getFuzzyPrefixLength

        public int getFuzzyPrefixLength()
        Get the prefix length for fuzzy queries.
        Returns the fuzzyPrefixLength.
      • setFuzzyPrefixLength

        public void setFuzzyPrefixLength​(int fuzzyPrefixLength)
        Set the prefix length for fuzzy queries. Default is 0.
        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.
      • getPhraseSlop

        public int getPhraseSlop()
        Gets the default slop for phrases.
      • setAllowSubQueryParsing

        public void setAllowSubQueryParsing​(boolean allowSubQueryParsing)
        Set to enable subqueries to be parsed. If now allowed, the default, a SyntaxError will likely be thrown. Here is the preferred syntax using local-params: {!prefix f=field v=foo} and here is the older one, using a magic field name: _query_:"{!prefix f=field v=foo}".
      • setSynonymQueryStyle

        public void setSynonymQueryStyle​(SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle)
        Set how overlapping query terms (ie synonyms) should be scored, as if they're the same term, picking highest scoring term, or OR'ing them together
        synonymQueryStyle - how to score terms that overlap see {SolrQueryParserBase.SynonymQueryStyle}
      • 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.

      • 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.
      • setMultiTermRewriteMethod

        public void setMultiTermRewriteMethod​( method)
        By default QueryParser uses MultiTermQuery.CONSTANT_SCORE_REWRITE when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyBooleanClauses" exception. However, if your application really needs to use the old-fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.
      • addClause

        protected void addClause​(List<> clauses,
                                 int conj,
                                 int mods,
      • addMultiTermClause

        protected void addMultiTermClause​(List<> clauses,
        Called from QueryParser's MultiTerm rule. Assumption: no conjunction or modifiers (conj == CONJ_NONE and mods == MOD_NONE)
      • newBooleanClause

        protected newBooleanClause​( q,
        Builds a new BooleanClause instance
        q - sub query
        occur - how this clause should occur when matching documents
        new BooleanClause instance
      • newPrefixQuery

        protected newPrefixQuery​(org.apache.lucene.index.Term prefix)
        Builds a new PrefixQuery instance
        prefix - Prefix term
        new PrefixQuery instance
      • newRegexpQuery

        protected newRegexpQuery​(org.apache.lucene.index.Term regexp)
        Builds a new RegexpQuery instance
        regexp - Regexp term
        new RegexpQuery instance
      • newGraphSynonymQuery

        protected newGraphSynonymQuery​(Iterator<> sidePathQueriesIterator)
        newGraphSynonymQuery in class org.apache.lucene.util.QueryBuilder
      • newSynonymQuery

        protected newSynonymQuery​(String field,
                                                                 org.apache.lucene.util.QueryBuilder.TermAndBoost[] terms)
        newSynonymQuery in class org.apache.lucene.util.QueryBuilder
      • newFuzzyQuery

        protected newFuzzyQuery​(org.apache.lucene.index.Term term,
                                                               float minimumSimilarity,
                                                               int prefixLength)
        Builds a new FuzzyQuery instance
        term - Term
        minimumSimilarity - minimum similarity
        prefixLength - prefix length
        new FuzzyQuery Instance
      • newMatchAllDocsQuery

        protected newMatchAllDocsQuery()
        Builds a new MatchAllDocsQuery instance
        new MatchAllDocsQuery instance
      • newWildcardQuery

        protected newWildcardQuery​(org.apache.lucene.index.Term t)
        Builds a new WildcardQuery instance
        t - wildcard term
        new WildcardQuery instance
      • getBooleanQuery

        protected getBooleanQuery​(List<> clauses)
                                                          throws SyntaxError
        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.

        clauses - List that contains BooleanClause instances to join.
        Resulting Query object.
      • escape

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

        protected getFieldQuery​(String field,
                                                               String queryText,
                                                               boolean quoted,
                                                               boolean raw)
                                                        throws SyntaxError
      • isRangeShouldBeProtectedFromReverse

        protected boolean isRangeShouldBeProtectedFromReverse​(String field,
                                                              String part1)
      • getRangeQuery

        protected getRangeQuery​(String field,
                                                               String part1,
                                                               String part2,
                                                               boolean startInclusive,
                                                               boolean endInclusive)
                                                        throws SyntaxError
      • getRangeQueryImpl

        protected getRangeQueryImpl​(String field,
                                                                   String part1,
                                                                   String part2,
                                                                   boolean startInclusive,
                                                                   boolean endInclusive)
                                                            throws SyntaxError
      • getExistenceQuery

        protected getExistenceQuery​(String field)