Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    QueryParserHelper<Query>
    StandardQueryParser
    PrecedenceQueryParser
    Implements
    ICommonQueryParserConfiguration
    Inherited Members
    QueryParserHelper<Query>.QueryNodeProcessor
    QueryParserHelper<Query>.SetQueryNodeProcessor(IQueryNodeProcessor)
    QueryParserHelper<Query>.SetSyntaxParser(ISyntaxParser)
    QueryParserHelper<Query>.SetQueryBuilder(IQueryBuilder<Query>)
    QueryParserHelper<Query>.QueryConfigHandler
    QueryParserHelper<Query>.QueryBuilder
    QueryParserHelper<Query>.SyntaxParser
    QueryParserHelper<Query>.SetQueryConfigHandler(QueryConfigHandler)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    Properties

    AllowLeadingWildcard

    Set to true to allow leading wildcard characters.

    When set, * 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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    See Also
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    bool
    See Also
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    LowercaseExpandedTerms

    Set to true to allow leading wildcard characters.

    When set, * 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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    TimeZone

    Gets or Sets the time zone.

    Declaration
    public virtual TimeZoneInfo TimeZone { get; set; }
    Property Value
    Type Description
    TimeZoneInfo
    See Also
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    QueryParserHelper<Query>.Parse(string, string)
    Exceptions
    Type Condition
    QueryNodeException

    if something wrong happens along the three phases

    See Also
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    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.

    Overrides
    object.ToString()
    See Also
    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder

    Implements

    ICommonQueryParserConfiguration

    See Also

    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.