org.apache.lucene.queryParser.precedence

## Class PrecedenceQueryParser

- java.lang.Object
- - org.apache.lucene.queryParser.precedence.PrecedenceQueryParser

- All Implemented Interfaces:
    PrecedenceQueryParserConstants

      public class PrecedenceQueryParser
      extends java.lang.Object
      implements PrecedenceQueryParserConstants

  Experimental query parser variant designed to handle operator precedence in a more sensible fashion than QueryParser. There are still some open issues with this parser. The following tests are currently failing in TestPrecedenceQueryParser and are disabled to make this test pass:
  - testSimple
  - testWildcard
  - testPrecedence
  This class is generated by JavaCC. The only method that clients should need to call is `parse(String)`. The syntax for query strings is as follows: A Query is a series of clauses. A clause may be prefixed by:
  - a plus (`+`) or a minus (`-`) sign, indicating that the clause is required or prohibited respectively; or
  - a term followed by a colon, indicating the field to be searched. This enables one to construct queries which search multiple fields.
  A clause may be either:
  - a term, indicating all the documents that contain this term; or
  - a nested query, enclosed in parentheses. Note that this may be used with a `+`/`-` prefix to require any of a set of terms.
  Thus, in BNF, the query grammar is:

         Query  ::= ( Clause )*
         Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )

  Examples of appropriately formatted queries can be found in the query syntax documentation.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator` | `AND_OPERATOR`
    `Token` | `jj_nt`
    `boolean` | `lookingAhead`
    `static org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator` | `OR_OPERATOR`
    `Token` | `token`
    `PrecedenceQueryParserTokenManager` | `token_source`

    - ### Fields inherited from interface org.apache.lucene.queryParser.precedence.PrecedenceQueryParserConstants

      `_ESCAPED_CHAR, _NUM_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RangeEx, RANGEEX_END, RANGEEX_GOOP, RANGEEX_QUOTED, RANGEEX_START, RANGEEX_TO, RangeIn, RANGEIN_END, RANGEIN_GOOP, RANGEIN_QUOTED, RANGEIN_START, RANGEIN_TO, RPAREN, TERM, tokenImage, WILDTERM`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PrecedenceQueryParser(CharStream stream)`
    `PrecedenceQueryParser(PrecedenceQueryParserTokenManager tm)`
    `PrecedenceQueryParser(java.lang.String f, Analyzer a)` Constructs a query parser.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addClause(java.util.List clauses, int conj, int modifier, Query q)`
    `protected void` | `addClause(java.util.Vector clauses, int conj, int modifier, Query q)` Deprecated. use `addClause(List, int, int, Query)` instead.
    `Query` | `andExpression(java.lang.String field)`
    `Query` | `Clause(java.lang.String field)`
    `int` | `Conjunction()`
    `void` | `disable_tracing()`
    `void` | `enable_tracing()`
    `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 `\`.
    `ParseException` | `generateParseException()`
    `Analyzer` | `getAnalyzer()`
    `protected Query` | `getBooleanQuery(java.util.List clauses)` Factory method for generating query, given a set of clauses.
    `protected Query` | `getBooleanQuery(java.util.List clauses, boolean disableCoord)` Factory method for generating query, given a set of clauses.
    `protected Query` | `getBooleanQuery(java.util.Vector clauses)` Deprecated. use `getBooleanQuery(List)` instead
    `protected Query` | `getBooleanQuery(java.util.Vector clauses, boolean disableCoord)` Deprecated. use `getBooleanQuery(List, boolean)` instead
    `org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator` | `getDefaultOperator()` Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
    `java.lang.String` | `getField()`
    `protected Query` | `getFieldQuery(java.lang.String field, java.lang.String queryText)`
    `protected Query` | `getFieldQuery(java.lang.String field, java.lang.String queryText, int slop)` Base implementation delegates to `getFieldQuery(String,String)`.
    `float` | `getFuzzyMinSim()` Get the minimal similarity for fuzzy queries.
    `int` | `getFuzzyPrefixLength()` Get the prefix length for fuzzy queries.
    `protected Query` | `getFuzzyQuery(java.lang.String field, java.lang.String termStr, float minSimilarity)` Factory method for generating a query (similar to `getWildcardQuery(java.lang.String, java.lang.String)`).
    `java.util.Locale` | `getLocale()` Returns current locale, allowing access by subclasses.
    `boolean` | `getLowercaseExpandedTerms()`
    `Token` | `getNextToken()`
    `int` | `getPhraseSlop()` Gets the default slop for phrases.
    `protected Query` | `getPrefixQuery(java.lang.String field, java.lang.String termStr)` Factory method for generating a query (similar to `getWildcardQuery(java.lang.String, java.lang.String)`).
    `protected Query` | `getRangeQuery(java.lang.String field, java.lang.String part1, java.lang.String part2, boolean inclusive)`
    `Token` | `getToken(int index)`
    `protected Query` | `getWildcardQuery(java.lang.String field, java.lang.String termStr)` Factory method for generating a query.
    `static void` | `main(java.lang.String[] args)` Command line tool to test QueryParser, using `SimpleAnalyzer`.
    `int` | `Modifier()`
    `Query` | `parse(java.lang.String expression)` Parses a query string, returning a `Query`.
    `Query` | `Query(java.lang.String field)`
    `void` | `ReInit(CharStream stream)`
    `void` | `ReInit(PrecedenceQueryParserTokenManager tm)`
    `void` | `setDefaultOperator(org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.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` | `setLocale(java.util.Locale locale)` Set locale used by date range parsing.
    `void` | `setLowercaseExpandedTerms(boolean lowercaseExpandedTerms)` Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not.
    `void` | `setPhraseSlop(int phraseSlop)` Sets the default slop for phrases.
    `Query` | `Term(java.lang.String field)`

    - ### 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 org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator AND_OPERATOR

    - #### OR_OPERATOR

          public static final org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator OR_OPERATOR

    - #### token_source

          public PrecedenceQueryParserTokenManager token_source

    - #### token

          public Token token

    - #### jj_nt

          public Token jj_nt

    - #### lookingAhead

          public boolean lookingAhead

  - ### Constructor Detail

    - #### PrecedenceQueryParser

          public PrecedenceQueryParser(java.lang.String f,
                                       Analyzer a)

      Constructs a query parser.
      Parameters:
        `f` - the default field for query terms.
        `a` - used to find terms in the query text.

    - #### PrecedenceQueryParser

          public PrecedenceQueryParser(CharStream stream)

    - #### PrecedenceQueryParser

          public PrecedenceQueryParser(PrecedenceQueryParserTokenManager tm)

  - ### Method Detail

    - #### parse

          public Query parse(java.lang.String expression)
                      throws ParseException

      Parses a query string, returning a `Query`.
      Parameters:
        `expression` - the query string to be parsed.
      Throws:
        `ParseException` - if the parsing fails

    - #### getAnalyzer

          public Analyzer getAnalyzer()

      Returns:
        Returns the analyzer.

    - #### getField

          public java.lang.String getField()

      Returns:
        Returns the field.

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

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

    - #### setDefaultOperator

          public void setDefaultOperator(org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.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 conjuction: the above mentioned query is parsed as `capital AND of AND Hungary`

    - #### getDefaultOperator

          public org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.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`.

    - #### getLowercaseExpandedTerms

          public boolean getLowercaseExpandedTerms()

      See Also:
        `setLowercaseExpandedTerms(boolean)`

    - #### setLocale

          public void setLocale(java.util.Locale locale)

      Set locale used by date range parsing.

    - #### getLocale

          public java.util.Locale getLocale()

      Returns current locale, allowing access by subclasses.

    - #### addClause

          protected void addClause(java.util.Vector clauses,
                                   int conj,
                                   int modifier,
                                   Query q)

      Deprecated. use `addClause(List, int, int, Query)` instead.

    - #### addClause

          protected void addClause(java.util.List clauses,
                                   int conj,
                                   int modifier,
                                   Query q)

    - #### getFieldQuery

          protected Query getFieldQuery(java.lang.String field,
                                        java.lang.String queryText)
                                 throws ParseException

      Throws:
        `ParseException` - throw in overridden method to disallow

    - #### getFieldQuery

          protected Query getFieldQuery(java.lang.String field,
                                        java.lang.String queryText,
                                        int slop)
                                 throws ParseException

      Base implementation delegates to `getFieldQuery(String,String)`. This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
      Throws:
        `ParseException` - throw in overridden method to disallow

    - #### getRangeQuery

          protected Query getRangeQuery(java.lang.String field,
                                        java.lang.String part1,
                                        java.lang.String part2,
                                        boolean inclusive)
                                 throws ParseException

      Throws:
        `ParseException` - throw in overridden method to disallow

    - #### getBooleanQuery

          protected Query getBooleanQuery(java.util.Vector clauses)
                                   throws ParseException

      Deprecated. use `getBooleanQuery(List)` instead
      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:
        `ParseException` - throw in overridden method to disallow

    - #### getBooleanQuery

          protected Query getBooleanQuery(java.util.List clauses)
                                   throws ParseException

      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:
        `ParseException` - throw in overridden method to disallow

    - #### getBooleanQuery

          protected Query getBooleanQuery(java.util.Vector clauses,
                                          boolean disableCoord)
                                   throws ParseException

      Deprecated. use `getBooleanQuery(List, boolean)` instead
      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.
        `disableCoord` - true if coord scoring should be disabled.
      Returns:
        Resulting `Query` object.
      Throws:
        `ParseException` - throw in overridden method to disallow

    - #### getBooleanQuery

          protected Query getBooleanQuery(java.util.List clauses,
                                          boolean disableCoord)
                                   throws ParseException

      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.
        `disableCoord` - true if coord scoring should be disabled.
      Returns:
        Resulting `Query` object.
      Throws:
        `ParseException` - throw in overridden method to disallow

    - #### getWildcardQuery

          protected Query getWildcardQuery(java.lang.String field,
                                           java.lang.String termStr)
                                    throws ParseException

      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.

      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

    - #### getPrefixQuery

          protected Query getPrefixQuery(java.lang.String field,
                                         java.lang.String termStr)
                                  throws ParseException

      Factory method for generating a query (similar to `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.

      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

    - #### getFuzzyQuery

          protected Query getFuzzyQuery(java.lang.String field,
                                        java.lang.String termStr,
                                        float minSimilarity)
                                 throws ParseException

      Factory method for generating a query (similar to `getWildcardQuery(java.lang.String, java.lang.String)`). Called when parser parses an input term token that has the fuzzy suffix (~) appended.
      Parameters:
        `field` - Name of the field query will use.
        `termStr` - Term token to use for building term for the query
      Returns:
        Resulting `Query` built for the term
      Throws:
        `ParseException` - throw in overridden method to disallow

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

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.lang.Exception

      Command line tool to test QueryParser, using `SimpleAnalyzer`. Usage:
      `java org.apache.lucene.queryParser.QueryParser <input>`
      Throws:
        `java.lang.Exception`

    - #### Conjunction

          public final int Conjunction()
                                throws ParseException

      Throws:
        `ParseException`

    - #### Modifier

          public final int Modifier()
                             throws ParseException

      Throws:
        `ParseException`

    - #### Query

          public final Query Query(java.lang.String field)
                            throws ParseException

      Throws:
        `ParseException`

    - #### andExpression

          public final Query andExpression(java.lang.String field)
                                    throws ParseException

      Throws:
        `ParseException`

    - #### Clause

          public final Query Clause(java.lang.String field)
                             throws ParseException

      Throws:
        `ParseException`

    - #### Term

          public final Query Term(java.lang.String field)
                           throws ParseException

      Throws:
        `ParseException`

    - #### ReInit

          public void ReInit(CharStream stream)

    - #### ReInit

          public void ReInit(PrecedenceQueryParserTokenManager tm)

    - #### getNextToken

          public final Token getNextToken()

    - #### getToken

          public final Token getToken(int index)

    - #### generateParseException

          public ParseException generateParseException()

    - #### enable_tracing

          public final void enable_tracing()

    - #### disable_tracing

          public final void disable_tracing()

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