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.
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.Flexible.Standard
Assembly: Lucene.Net.QueryParser.dll
Syntax
public class StandardQueryParser : QueryParserHelper<Query>, ICommonQueryParserConfiguration
Constructors
| Improve this Doc View SourceStandardQueryParser()
Constructs a StandardQueryParser object.
Declaration
public StandardQueryParser()
StandardQueryParser(Analyzer)
Constructs a StandardQueryParser object and sets an
StandardQueryParser qp = new StandardQueryParser();
qp.QueryConfigHandler.Analyzer = analyzer;
Declaration
public StandardQueryParser(Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer | the analyzer to be used by this query parser helper |
Properties
| Improve this Doc View SourceAllowLeadingWildcard
Set to true
to allow leading wildcard characters.
When set, *
or ?
are allowed as the first
character of a
Default: false.
Declaration
public virtual bool AllowLeadingWildcard { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Analyzer
Declaration
public virtual Analyzer Analyzer { get; set; }
Property Value
Type | Description |
---|---|
Analyzer |
DateResolution
Gets the default
Declaration
public virtual DateTools.Resolution DateResolution { get; }
Property Value
Type | Description |
---|---|
DateTools.Resolution |
DateResolutionMap
Gets or Sets the field to
Declaration
public virtual IDictionary<string, DateTools.Resolution?> DateResolutionMap { get; set; }
Property Value
Type | Description |
---|---|
IDictionary<System.String, System.Nullable<DateTools.Resolution>> |
DefaultOperator
Gets or Sets the boolean operator of the QueryParser. In default mode (
OR) terms without any modifiers are considered optional:
for example capital of Hungary
is equal to
capital OR of OR Hungary
.
In AND mode terms are considered to be in conjunction: the
above mentioned query is parsed as capital AND of AND Hungary
Declaration
public virtual StandardQueryConfigHandler.Operator DefaultOperator { get; set; }
Property Value
Type | Description |
---|---|
StandardQueryConfigHandler.Operator |
EnablePositionIncrements
Set to true
to enable position increments in result query.
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.
Declaration
public virtual bool EnablePositionIncrements { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
FieldsBoost
Gets or Sets the field to boost map used to set boost for each field.
Declaration
public virtual IDictionary<string, float?> FieldsBoost { get; set; }
Property Value
Type | Description |
---|---|
IDictionary<System.String, System.Nullable<System.Single>> |
FuzzyMinSim
Gets or Sets the minimum similarity for fuzzy queries. Default is defined on
Declaration
public virtual float FuzzyMinSim { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
FuzzyPrefixLength
Gets or Sets the prefix length for fuzzy queries. Default is 0.
Declaration
public virtual int FuzzyPrefixLength { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Locale
Gets or Sets current locale, allowing access by subclasses. Used by date range parsing
Declaration
public virtual CultureInfo Locale { get; set; }
Property Value
Type | Description |
---|---|
CultureInfo |
LowercaseExpandedTerms
Set to true
to allow leading wildcard characters.
When set, *
or ?
are allowed as the first
character of a
Default: false.
Declaration
public virtual bool LowercaseExpandedTerms { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
MultiTermRewriteMethod
By default, it uses
Declaration
public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
Property Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
NumericConfigMap
Declaration
public virtual IDictionary<string, NumericConfig> NumericConfigMap { get; set; }
Property Value
Type | Description |
---|---|
IDictionary<System.String, NumericConfig> |
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.
Declaration
public virtual int PhraseSlop { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
TimeZone
Declaration
public virtual TimeZoneInfo TimeZone { get; set; }
Property Value
Type | Description |
---|---|
TimeZoneInfo |
Methods
| Improve this Doc View SourceGetMultiFields()
Returns the fields used to expand the query when the field for a
certain query is null
Declaration
public virtual string[] GetMultiFields()
Returns
Type | Description |
---|---|
System.String[] | the fields used to expand the query |
Parse(String, String)
Overrides Parse(String, String) so it casts the
return object to
Declaration
public override Query Parse(string query, string defaultField)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | the query string |
System.String | defaultField | the default field used by the text parser |
Returns
Type | Description |
---|---|
Query | the object built from the query |
Overrides
Exceptions
Type | Condition |
---|---|
QueryNodeException | if something wrong happens along the three phases |
SetDateResolution(DateTools.Resolution)
Sets the default
Declaration
public virtual void SetDateResolution(DateTools.Resolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
DateTools.Resolution | dateResolution | the default |
SetDateResolution(IDictionary<String, Nullable<DateTools.Resolution>>)
Sets the
Declaration
public virtual void SetDateResolution(IDictionary<string, DateTools.Resolution?> dateRes)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<System.String, System.Nullable<DateTools.Resolution>> | dateRes | a collection that maps a field to its |
SetDefaultPhraseSlop(Int32)
Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
Declaration
public virtual void SetDefaultPhraseSlop(int defaultPhraseSlop)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | defaultPhraseSlop |
SetMultiFields(String[])
Set the fields a query should be expanded to when the field is
null
Declaration
public virtual void SetMultiFields(string[] fields)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fields | the fields used to expand the query |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |