Class StandardQueryParser
This class is a helper that enables users to easily use the Lucene query parser.
To construct a Query object from a query string, use the Parse(String, String) method:
StandardQueryParser queryParserHelper = new StandardQueryParser();
Query query = queryParserHelper.Parse("a AND b", "defaultField");
To change any configuration before parsing the query string do, for example:
// the query config handler returned by StandardQueryParser is a
// StandardQueryConfigHandler
queryParserHelper.QueryConfigHandler.Analyzer = new WhitespaceAnalyzer();
The syntax for query strings is as follows (copied from the old QueryParser javadoc):
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 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.
Query ::= ( Clause )*
Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
Examples of appropriately formatted queries can be found in the query syntax documentation.
The text parser used by this helper is a StandardSyntaxParser.
The query node processor used by this helper is a StandardQueryNodeProcessorPipeline.
The builder used by this helper is a StandardQueryTreeBuilder.
Inherited Members
Assembly: Lucene.Net.QueryParser.dll
Syntax
[Serializable]
public class StandardQueryParser : QueryParserHelper<Query>, ICommonQueryParserConfiguration
Constructors
Name | Description |
---|---|
StandardQueryParser() | Constructs a StandardQueryParser object. |
StandardQueryParser(Analyzer) | Constructs a StandardQueryParser object and sets an Analyzer to it. The same as:
|
Properties
Name | Description |
---|---|
AllowLeadingWildcard | Set to
When set, Default: false. |
Analyzer | |
DateResolution | Gets the default DateTools.Resolution used for certain field when no DateTools.Resolution is defined for this field. |
DateResolutionMap | Gets or Sets the field to |
DefaultOperator | Gets or Sets the boolean operator of the QueryParser. In default mode (
OR) terms without any modifiers are considered optional:
for example
In AND mode terms are considered to be in conjunction: the
above mentioned query is parsed as |
EnablePositionIncrements | Set to When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g. a StopFilter increases the position increment of the token that follows an omitted token. Default: false. |
FieldsBoost | Gets or Sets the field to boost map used to set boost for each field. |
FuzzyMinSim | Gets or Sets the minimum similarity for fuzzy queries. Default is defined on DefaultMinSimilarity. |
FuzzyPrefixLength | Gets or Sets the prefix length for fuzzy queries. Default is 0. |
Locale | Gets or Sets current locale, allowing access by subclasses. Used by date range parsing |
LowercaseExpandedTerms | Set to
When set, Default: false. |
MultiTermRewriteMethod | By default, it uses CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a prefix, wildcard and range queries. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any Exception due to too many listeners. However, if your application really needs to use the old-fashioned boolean queries expansion rewriting and the above points are not relevant then use this change the rewrite method. |
NumericConfigMap | |
PhraseSlop | Gets or Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero. NOTE: Setter is deprecated. |
TimeZone |
Methods
Name | Description |
---|---|
GetMultiFields() | Returns the fields used to expand the query when the field for a
certain query is |
Parse(String, String) | Overrides Parse(String, String) so it casts the return object to Query. For more reference about this method, check Parse(String, String). |
SetDateResolution(DateTools.Resolution) | Sets the default DateTools.Resolution used for certain field when no DateTools.Resolution is defined for this field. |
SetDateResolution(IDictionary<String, Nullable<DateTools.Resolution>>) | Sets the DateTools.Resolution used for each field |
SetDefaultPhraseSlop(Int32) | Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero. |
SetMultiFields(String[]) | Set the fields a query should be expanded to when the field is
|
ToString() |