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:
queryParserHelper.Analyzer = new WhitespaceAnalyzer();
queryParserHelper.AllowLeadingWildcard = true;
// Or alternativley use the query config handler returned by StandardQueryParser which is a
// StandardQueryConfigHandler:
queryParserHelper.QueryConfigHandler.Set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
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 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 ")" )
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
StandardQueryParser()
Constructs a StandardQueryParser object.
Declaration
public StandardQueryParser()
See Also
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 |
---|---|---|
Analyzer | analyzer | the analyzer to be used by this query parser helper |
See Also
Properties
AllowLeadingWildcard
Set to true
to allow leading wildcard characters.
*
or ?
are allowed as the first
character of a Lucene.Net.Search.PrefixQuery and Lucene.Net.Search.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 |
---|---|
bool |
See Also
Analyzer
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:
queryParserHelper.Analyzer = new WhitespaceAnalyzer();
queryParserHelper.AllowLeadingWildcard = true;
// Or alternativley use the query config handler returned by StandardQueryParser which is a
// StandardQueryConfigHandler:
queryParserHelper.QueryConfigHandler.Set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
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 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 ")" )
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.
Declaration
public virtual Analyzer Analyzer { get; set; }
Property Value
Type | Description |
---|---|
Analyzer |
See Also
DateResolution
Gets the default Lucene.Net.Documents.DateResolution used for certain field when no Lucene.Net.Documents.DateResolution is defined for this field.
Declaration
public virtual DateResolution? DateResolution { get; }
Property Value
Type | Description |
---|---|
DateResolution? |
See Also
DateResolutionMap
Gets or Sets the field to Lucene.Net.Documents.DateResolution map used to normalize each date field.
Declaration
public virtual IDictionary<string, DateResolution> DateResolutionMap { get; set; }
Property Value
Type | Description |
---|---|
IDictionary<string, DateResolution> |
See Also
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
.
capital AND of AND Hungary
Declaration
public virtual StandardQueryConfigHandler.Operator DefaultOperator { get; set; }
Property Value
Type | Description |
---|---|
StandardQueryConfigHandler.Operator |
See Also
EnablePositionIncrements
Set to true
to enable position increments in result query.
Declaration
public virtual bool EnablePositionIncrements { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
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<string, float> |
See Also
FuzzyMinSim
Gets or Sets the minimum similarity for fuzzy queries. Default is defined on Lucene.Net.Search.FuzzyQuery.DefaultMinSimilarity.
Declaration
public virtual float FuzzyMinSim { get; set; }
Property Value
Type | Description |
---|---|
float |
See Also
FuzzyPrefixLength
Gets or Sets the prefix length for fuzzy queries. Default is 0.
Declaration
public virtual int FuzzyPrefixLength { get; set; }
Property Value
Type | Description |
---|---|
int |
See Also
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 |
See Also
LowercaseExpandedTerms
Set to true
to allow leading wildcard characters.
*
or ?
are allowed as the first
character of a Lucene.Net.Search.PrefixQuery and Lucene.Net.Search.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 |
---|---|
bool |
See Also
MultiTermRewriteMethod
By default, it uses Lucene.Net.Search.MultiTermQuery.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 |
---|---|
MultiTermQuery.RewriteMethod |
See Also
NumericConfigMap
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:
queryParserHelper.Analyzer = new WhitespaceAnalyzer();
queryParserHelper.AllowLeadingWildcard = true;
// Or alternativley use the query config handler returned by StandardQueryParser which is a
// StandardQueryConfigHandler:
queryParserHelper.QueryConfigHandler.Set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
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 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 ")" )
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.
Declaration
public virtual IDictionary<string, NumericConfig> NumericConfigMap { get; set; }
Property Value
Type | Description |
---|---|
IDictionary<string, NumericConfig> |
See Also
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 |
---|---|
int |
See Also
TimeZone
Gets or Sets the time zone.
Declaration
public virtual TimeZoneInfo TimeZone { get; set; }
Property Value
Type | Description |
---|---|
TimeZoneInfo |
See Also
Methods
GetMultiFields()
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 |
---|---|
string[] | the fields used to expand the query |
See Also
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 |
---|---|---|
string | query | the query string |
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 |
See Also
SetDateResolution(DateResolution)
Sets the default Lucene.Net.Documents.DateResolution used for certain field when no Lucene.Net.Documents.DateResolution is defined for this field.
Declaration
public virtual void SetDateResolution(DateResolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
DateResolution | dateResolution | the default Lucene.Net.Documents.DateResolution |
See Also
SetDateResolution(IDictionary<string, DateResolution>)
Sets the Lucene.Net.Documents.DateResolution used for each field
Declaration
[Obsolete("Use DateResolutionMap property instead.")]
public virtual void SetDateResolution(IDictionary<string, DateResolution> dateRes)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<string, DateResolution> | dateRes | a collection that maps a field to its Lucene.Net.Documents.DateResolution |
See Also
SetDefaultPhraseSlop(int)
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 |
---|---|---|
int | defaultPhraseSlop |
See Also
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 |
---|---|---|
string[] | fields | the fields used to expand the query |
See Also
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |