This class is generated by JavaCC. The most important method is {@link #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 (
    CopyC#
    +
    ) or a minus (
    CopyC#
    -
    ) 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
    CopyC#
    +
    /
    CopyC#
    -
    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.

In {@link TermRangeQuery}s, QueryParser tries to detect date values, e.g. date:[6/1/2005 TO 6/4/2005] produces a range query that searches for "date" fields between 2005-06-01 and 2005-06-04. Note that the format of the accepted input depends on {@link #SetLocale(Locale) the locale}. By default a date is converted into a search term using the deprecated {@link DateField} for compatibility reasons. To use the new {@link DateTools} to convert dates, a {@link Lucene.Net.Documents.DateTools.Resolution} has to be set.

The date resolution that shall be used for RangeQueries can be set using {@link #SetDateResolution(DateTools.Resolution)} or {@link #SetDateResolution(String, DateTools.Resolution)}. The former sets the default date resolution for all fields, whereas the latter can be used to set field specific date resolutions. Field specific date resolutions take, if set, precedence over the default date resolution.

If you use neither {@link DateField} nor {@link DateTools} in your index, you can create your own query parser that inherits QueryParser and overwrites {@link #GetRangeQuery(String, String, String, boolean)} to use a different method for date conversion.

Note that QueryParser is not thread-safe.

NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.

NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created. NOTE: You must specify the required {@link Version} compatibility when creating QueryParser:

  • As of 2.9, {@link #SetEnablePositionIncrements} is true by default.

The QueryParser..::..Operator type exposes the following members.

Methods

  NameDescription
Public methodEquals
Resolves the deserialized instance to the local reference for accurate equals() and == comparisons.
(Inherited from Parameter.)
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString (Inherited from Parameter.)

Fields

  NameDescription
Public fieldStatic memberAND
Public fieldStatic memberOR

See Also