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 Lucene.Net.Analysis.Analyzer to it. The same as:
StandardQueryParser qp = new StandardQueryParser();
qp.QueryConfigHandler.Analyzer = analyzer;
Declaration
public StandardQueryParser(Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Analysis.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 PrefixQuery and WildcardQuery. Note that this can produce
very slow queries on big indexes.
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 |
---|---|
Lucene.Net.Analysis.Analyzer |
DateResolution
Gets the default Lucene.Net.Documents.DateTools.Resolution used for certain field when no Lucene.Net.Documents.DateTools.Resolution is defined for this field.
Declaration
public virtual DateTools.Resolution DateResolution { get; }
Property Value
Type | Description |
---|---|
Lucene.Net.Documents.DateTools.Resolution |
DateResolutionMap
Gets or Sets the field to
Declaration
public virtual IDictionary<string, DateTools.Resolution?> DateResolutionMap { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Nullable<Lucene.Net.Documents.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 Lucene.Net.Analysis.Core.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 |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Nullable<System.Single>> |
FuzzyMinSim
Gets or Sets the minimum similarity for fuzzy queries. Default is defined on DefaultMinSimilarity.
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 |
---|---|
System.Globalization.CultureInfo |
LowercaseExpandedTerms
Set to true
to allow leading wildcard characters.
When set, *
or ?
are allowed as the first
character of a PrefixQuery and WildcardQuery. Note that this can produce
very slow queries on big indexes.
Default: false.
Declaration
public virtual bool LowercaseExpandedTerms { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
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.
Declaration
public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
Property Value
Type | Description |
---|---|
Lucene.Net.Search.MultiTermQuery.RewriteMethod |
NumericConfigMap
Declaration
public virtual IDictionary<string, NumericConfig> NumericConfigMap { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.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 |
---|---|
System.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 Lucene.Net.Search.Query. For more reference about this method, check Parse(String, String).
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 |
---|---|
Lucene.Net.Search.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 Lucene.Net.Documents.DateTools.Resolution used for certain field when no Lucene.Net.Documents.DateTools.Resolution is defined for this field.
Declaration
public virtual void SetDateResolution(DateTools.Resolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Documents.DateTools.Resolution | dateResolution | the default Lucene.Net.Documents.DateTools.Resolution |
SetDateResolution(IDictionary<String, Nullable<DateTools.Resolution>>)
Sets the Lucene.Net.Documents.DateTools.Resolution used for each field
Declaration
[Obsolete("Use DateResolutionMap property instead.")]
public virtual void SetDateResolution(IDictionary<string, DateTools.Resolution?> dateRes)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<System.String, System.Nullable<Lucene.Net.Documents.DateTools.Resolution>> | dateRes | a collection that maps a field to its Lucene.Net.Documents.DateTools.Resolution |
SetDefaultPhraseSlop(Int32)
Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
Declaration
[Obsolete("Use PhraseSlop property setter instead.")]
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 |