• 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:

    // 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 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
    System.Object
    QueryParserHelper<Lucene.Net.Search.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)
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Lucene.Net.QueryParsers.Flexible.Standard
    Assembly: Lucene.Net.QueryParser.dll
    Syntax
    public class StandardQueryParser : QueryParserHelper<Query>, ICommonQueryParserConfiguration

    Constructors

    | Improve this Doc View Source

    StandardQueryParser()

    Constructs a StandardQueryParser object.

    Declaration
    public StandardQueryParser()
    | Improve this Doc View Source

    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 Source

    AllowLeadingWildcard

    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
    | Improve this Doc View Source

    Analyzer

    Declaration
    public virtual Analyzer Analyzer { get; set; }
    Property Value
    Type Description
    Lucene.Net.Analysis.Analyzer
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    DateResolutionMap

    Gets or Sets the field to map used to normalize each date field.

    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>>
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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>>
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    NumericConfigMap

    Declaration
    public virtual IDictionary<string, NumericConfig> NumericConfigMap { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.IDictionary<System.String, NumericConfig>
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    TimeZone

    Declaration
    public virtual TimeZoneInfo TimeZone { get; set; }
    Property Value
    Type Description
    System.TimeZoneInfo

    Methods

    | Improve this Doc View Source

    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
    System.String[]

    the fields used to expand the query

    | Improve this Doc View Source

    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
    Lucene.Net.QueryParsers.Flexible.Core.QueryParserHelper<Lucene.Net.Search.Query>.Parse(System.String, System.String)
    Exceptions
    Type Condition
    QueryNodeException

    if something wrong happens along the three phases

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.Object.ToString()

    Implements

    ICommonQueryParserConfiguration

    See Also

    StandardQueryParser
    StandardQueryConfigHandler
    StandardSyntaxParser
    StandardQueryNodeProcessorPipeline
    StandardQueryTreeBuilder
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)