org.apache.solr.parser

## Class SolrQueryParserBase

- java.lang.Object
- - org.apache.lucene.util.QueryBuilder
  - - org.apache.solr.parser.SolrQueryParserBase

- Direct Known Subclasses:
    QueryParser

      public abstract class SolrQueryParserBase
      extends 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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SolrQueryParserBase.MagicFieldName` Identifies the list of all known "magic fields" that trigger special parsing behavior

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static QueryParser.Operator` | `AND_OPERATOR` Alternative form of QueryParser.Operator.AND
    `protected String` | `explicitField`
    `static QueryParser.Operator` | `OR_OPERATOR` Alternative form of QueryParser.Operator.OR
    `protected QParser` | `parser`
    `protected IndexSchema` | `schema`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `SolrQueryParserBase()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addClause(List<BooleanClause> clauses, int conj, int mods, Query q)`
    `protected String` | `analyzeIfMultitermTermText(String field, String part, FieldType fieldType)`
    `static String` | `escape(String s)` Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding `\`.
    `boolean` | `getAllowLeadingWildcard()`
    `boolean` | `getAutoGeneratePhraseQueries()`
    `protected Query` | `getBooleanQuery(List<BooleanClause> clauses)` Factory method for generating query, given a set of clauses.
    `String` | `getDefaultField()`
    `QueryParser.Operator` | `getDefaultOperator()` Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
    `String` | `getExplicitField()` For a fielded query, returns the actual field specified (i.e.
    `String` | `getField(String fieldName)` Handles the default field if null is passed
    `protected Query` | `getFieldQuery(String field, String queryText, boolean quoted)`
    `protected Query` | `getFieldQuery(String field, String queryText, int slop)` Base implementation delegates to `getFieldQuery(String,String,boolean)`.
    `float` | `getFuzzyMinSim()` Get the minimal similarity for fuzzy queries.
    `int` | `getFuzzyPrefixLength()` Get the prefix length for fuzzy queries.
    `protected Query` | `getFuzzyQuery(String field, String termStr, float minSimilarity)`
    `protected Query` | `getLocalParams(String qfield, String lparams)`
    `MultiTermQuery.RewriteMethod` | `getMultiTermRewriteMethod()`
    `int` | `getPhraseSlop()` Gets the default slop for phrases.
    `protected Query` | `getPrefixQuery(String field, String termStr)`
    `protected Query` | `getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)`
    `protected Query` | `getRegexpQuery(String field, String termStr)`
    `protected ReversedWildcardFilterFactory` | `getReversedWildcardFilterFactory(FieldType fieldType)`
    `protected Query` | `getWildcardQuery(String field, String termStr)`
    `void` | `init(Version matchVersion, String defaultField, QParser parser)`
    `protected BooleanClause` | `newBooleanClause(Query q, BooleanClause.Occur occur)` Builds a new BooleanClause instance
    `protected Query` | `newFieldQuery(Analyzer analyzer, String field, String queryText, boolean quoted)`
    `protected Query` | `newFuzzyQuery(Term term, float minimumSimilarity, int prefixLength)` Builds a new FuzzyQuery instance
    `protected Query` | `newMatchAllDocsQuery()` Builds a new MatchAllDocsQuery instance
    `protected Query` | `newPrefixQuery(Term prefix)` Builds a new PrefixQuery instance
    `protected Query` | `newRegexpQuery(Term regexp)` Builds a new RegexpQuery instance
    `protected Query` | `newWildcardQuery(Term t)` Builds a new WildcardQuery instance
    `Query` | `parse(String query)` Parses a query string, returning a `Query`.
    `abstract void` | `ReInit(CharStream stream)`
    `void` | `setAllowLeadingWildcard(boolean allowLeadingWildcard)` Set to `true` to allow leading wildcard characters.
    `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.
    `void` | `setDefaultOperator(QueryParser.Operator op)` Sets the boolean operator of the QueryParser.
    `void` | `setFuzzyMinSim(float fuzzyMinSim)` Set the minimum similarity for fuzzy queries.
    `void` | `setFuzzyPrefixLength(int fuzzyPrefixLength)` Set the prefix length for fuzzy queries.
    `void` | `setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)` By default QueryParser uses `MultiTermQuery.CONSTANT_SCORE_REWRITE` when creating a PrefixQuery, WildcardQuery or RangeQuery.
    `void` | `setPhraseSlop(int phraseSlop)` Sets the default slop for phrases.
    `abstract Query` | `TopLevelQuery(String field)`

    - ### Methods inherited from class org.apache.lucene.util.QueryBuilder

      `createBooleanQuery, createBooleanQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, newBooleanQuery, newMultiPhraseQueryBuilder, newSynonymQuery, newTermQuery, setAnalyzer, setEnablePositionIncrements`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### AND_OPERATOR

          public static final QueryParser.Operator AND_OPERATOR

      Alternative form of QueryParser.Operator.AND

    - #### OR_OPERATOR

          public static final QueryParser.Operator OR_OPERATOR

      Alternative form of QueryParser.Operator.OR

    - #### schema

          protected IndexSchema schema

    - #### parser

          protected QParser parser

    - #### explicitField

          protected String explicitField

  - ### Constructor Detail

    - #### SolrQueryParserBase

          protected SolrQueryParserBase()

  - ### Method Detail

    - #### ReInit

          public abstract void ReInit(CharStream stream)

    - #### TopLevelQuery

          public abstract Query TopLevelQuery(String field)
                                       throws ParseException,
                                              SyntaxError

      Throws:
        `ParseException`
        `SyntaxError`

    - #### init

          public void init(Version matchVersion,
                           String defaultField,
                           QParser parser)

    - #### parse

          public Query parse(String query)
                      throws SyntaxError

      Parses a query string, returning a `Query`.
      Parameters:
        `query` - the query string to be parsed.
      Throws:
        `SyntaxError`

    - #### getDefaultField

          public String getDefaultField()

      Returns:
        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"

    - #### getAutoGeneratePhraseQueries

          public final boolean getAutoGeneratePhraseQueries()

      See Also:
        `setAutoGeneratePhraseQueries(boolean)`

    - #### 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:
        Returns the fuzzyPrefixLength.

    - #### setFuzzyPrefixLength

          public void setFuzzyPrefixLength(int fuzzyPrefixLength)

      Set the prefix length for fuzzy queries. Default is 0.
      Parameters:
        `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.

    - #### 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.

    - #### getAllowLeadingWildcard

          public boolean getAllowLeadingWildcard()

      See Also:
        `setAllowLeadingWildcard(boolean)`

    - #### 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(MultiTermQuery.RewriteMethod 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.

    - #### getMultiTermRewriteMethod

          public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod()

      See Also:
        `setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod)`

    - #### addClause

          protected void addClause(List<BooleanClause> clauses,
                                   int conj,
                                   int mods,
                                   Query q)

    - #### newFieldQuery

          protected Query newFieldQuery(Analyzer analyzer,
                                        String field,
                                        String queryText,
                                        boolean quoted)
                                 throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getFieldQuery

          protected Query getFieldQuery(String field,
                                        String queryText,
                                        int slop)
                                 throws SyntaxError

      Base implementation delegates to `getFieldQuery(String,String,boolean)`. This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
      Throws:
        `SyntaxError`

    - #### newBooleanClause

          protected BooleanClause newBooleanClause(Query q,
                                                   BooleanClause.Occur occur)

      Builds a new BooleanClause instance
      Parameters:
        `q` - sub query
        `occur` - how this clause should occur when matching documents
      Returns:
        new BooleanClause instance

    - #### newPrefixQuery

          protected Query newPrefixQuery(Term prefix)

      Builds a new PrefixQuery instance
      Parameters:
        `prefix` - Prefix term
      Returns:
        new PrefixQuery instance

    - #### newRegexpQuery

          protected Query newRegexpQuery(Term regexp)

      Builds a new RegexpQuery instance
      Parameters:
        `regexp` - Regexp term
      Returns:
        new RegexpQuery instance

    - #### newFuzzyQuery

          protected Query newFuzzyQuery(Term term,
                                        float minimumSimilarity,
                                        int prefixLength)

      Builds a new FuzzyQuery instance
      Parameters:
        `term` - Term
        `minimumSimilarity` - minimum similarity
        `prefixLength` - prefix length
      Returns:
        new FuzzyQuery Instance

    - #### newMatchAllDocsQuery

          protected Query newMatchAllDocsQuery()

      Builds a new MatchAllDocsQuery instance
      Returns:
        new MatchAllDocsQuery instance

    - #### newWildcardQuery

          protected Query newWildcardQuery(Term t)

      Builds a new WildcardQuery instance
      Parameters:
        `t` - wildcard term
      Returns:
        new WildcardQuery instance

    - #### getBooleanQuery

          protected Query getBooleanQuery(List<BooleanClause> 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.
      Parameters:
        `clauses` - List that contains `BooleanClause` instances to join.
      Returns:
        Resulting `Query` object.
      Throws:
        `SyntaxError`

    - #### escape

          public static String escape(String s)

      Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding `\`.

    - #### getReversedWildcardFilterFactory

          protected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType)

    - #### analyzeIfMultitermTermText

          protected String analyzeIfMultitermTermText(String field,
                                                      String part,
                                                      FieldType fieldType)

    - #### getFieldQuery

          protected Query getFieldQuery(String field,
                                        String queryText,
                                        boolean quoted)
                                 throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getRangeQuery

          protected Query getRangeQuery(String field,
                                        String part1,
                                        String part2,
                                        boolean startInclusive,
                                        boolean endInclusive)
                                 throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getPrefixQuery

          protected Query getPrefixQuery(String field,
                                         String termStr)
                                  throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getWildcardQuery

          protected Query getWildcardQuery(String field,
                                           String termStr)
                                    throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getRegexpQuery

          protected Query getRegexpQuery(String field,
                                         String termStr)
                                  throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getFuzzyQuery

          protected Query getFuzzyQuery(String field,
                                        String termStr,
                                        float minSimilarity)
                                 throws SyntaxError

      Throws:
        `SyntaxError`

    - #### getLocalParams

          protected Query getLocalParams(String qfield,
                                         String lparams)
                                  throws SyntaxError

      Throws:
        `SyntaxError`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.