QueryParser
This class is generated by JavaCC. The most important method is .parse.
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; ora 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 ")" )
*In TermRangeQuerys, 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 .setLocale. A org.gnit.lucenekmp.document.DateTools.Resolution has to be set, if you want to use DateTools for date conversion.
The date resolution that shall be used for RangeQueries can be set using .setDateResolution or .setDateResolution. 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 don't use DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites .getRangeQuery 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.
Inheritors
Types
The default operator for parsing queries. Use QueryParserBase.setDefaultOperator to change it.
Properties
Set to true to allow leading wildcard characters.
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.
Sets the default Resolution used for certain field when no Resolution is defined for this field.
Set to true to enable position increments in result query.
Set the minimum similarity for fuzzy queries. Default is 2f.
Set the prefix length for fuzzy queries. Default is 0.
The actual operator that parser uses to combine query terms
Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
Generated Token Manager.
Functions
Disable tracing.
Returns a String where the escape char has been removed, or kept only once if there was a double escape.
Enable tracing.
Generate ParseException.
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.
Returns the first query if splitOnWhitespace=true or otherwise the entire produced query
Sets the date resolution used by RangeQueries for a specific field.
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
Whether query text should be split on whitespace prior to analysis. Default is {@value #DEFAULT_SPLIT_ON_WHITESPACE}.
Trace enabled.