Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class QueryParser

    This class is generated by JavaCC. The most important method is Parse(String).

    The syntax for query strings is as follows: 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.

    In Lucene.Net.Search.TermRangeQuerys, QueryParser tries to detect date values, e.g. date:[6/1/2005 TO 6/4/2005] produces a range query that searches for "date" fields between 2005-06-01 and 2005-06-04. Note that the format of the accepted input depends on the System.Globalization.CultureInfo. A Lucene.Net.Documents.DateResolution has to be set, if you want to use Lucene.Net.Documents.DateTools for date conversion.

    The date resolution that shall be used for RangeQueries can be set using SetDateResolution(DateResolution) or SetDateResolution(String, DateResolution). The former sets the default date resolution for all fields, whereas the latter can be used to set field specific date resolutions. Field specific date resolutions take, if set, precedence over the default date resolution.

    If you don't use Lucene.Net.Documents.DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites GetRangeQuery(String, String, String, Boolean, Boolean) to use a different method for date conversion.

    Note that QueryParser is not thread-safe.

    NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.

    NOTE: You must specify the required Lucene.Net.Util.LuceneVersion compatibility when creating QueryParser:

    • As of 3.1, AutoGeneratePhraseQueries is false by default.

    Inheritance
    System.Object
    Lucene.Net.Util.QueryBuilder
    QueryParserBase
    QueryParser
    AnalyzingQueryParser
    MultiFieldQueryParser
    ComplexPhraseQueryParser
    ExtendableQueryParser
    Implements
    ICommonQueryParserConfiguration
    Inherited Members
    QueryParserBase.CONJ_NONE
    QueryParserBase.CONJ_AND
    QueryParserBase.CONJ_OR
    QueryParserBase.MOD_NONE
    QueryParserBase.MOD_NOT
    QueryParserBase.MOD_REQ
    QueryParserBase.AND_OPERATOR
    QueryParserBase.OR_OPERATOR
    QueryParserBase.m_field
    QueryParserBase.Init(LuceneVersion, String, Analyzer)
    QueryParserBase.Parse(String)
    QueryParserBase.Field
    QueryParserBase.AutoGeneratePhraseQueries
    QueryParserBase.FuzzyMinSim
    QueryParserBase.FuzzyPrefixLength
    QueryParserBase.PhraseSlop
    QueryParserBase.AllowLeadingWildcard
    QueryParserBase.DefaultOperator
    QueryParserBase.LowercaseExpandedTerms
    QueryParserBase.MultiTermRewriteMethod
    QueryParserBase.Locale
    QueryParserBase.TimeZone
    QueryParserBase.SetDateResolution(DateResolution)
    QueryParserBase.SetDateResolution(String, DateResolution)
    QueryParserBase.GetDateResolution(String)
    QueryParserBase.AnalyzeRangeTerms
    QueryParserBase.AddClause(IList<BooleanClause>, Int32, Int32, Query)
    QueryParserBase.GetFieldQuery(String, String, Boolean)
    QueryParserBase.NewFieldQuery(Analyzer, String, String, Boolean)
    QueryParserBase.GetFieldQuery(String, String, Int32)
    QueryParserBase.GetRangeQuery(String, String, String, Boolean, Boolean)
    QueryParserBase.NewBooleanClause(Query, Occur)
    QueryParserBase.NewPrefixQuery(Term)
    QueryParserBase.NewRegexpQuery(Term)
    QueryParserBase.NewFuzzyQuery(Term, Single, Int32)
    QueryParserBase.AnalyzeMultitermTerm(String, String, Analyzer)
    QueryParserBase.NewRangeQuery(String, String, String, Boolean, Boolean)
    QueryParserBase.NewMatchAllDocsQuery()
    QueryParserBase.NewWildcardQuery(Term)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>, Boolean)
    QueryParserBase.GetWildcardQuery(String, String)
    QueryParserBase.GetRegexpQuery(String, String)
    QueryParserBase.GetPrefixQuery(String, String)
    QueryParserBase.GetFuzzyQuery(String, String, Single)
    QueryParserBase.Escape(String)
    QueryBuilder.CreateBooleanQuery(String, String)
    QueryBuilder.CreateBooleanQuery(String, String, Occur)
    QueryBuilder.CreatePhraseQuery(String, String)
    QueryBuilder.CreatePhraseQuery(String, String, Int32)
    QueryBuilder.CreateMinShouldMatchQuery(String, String, Single)
    Lucene.Net.Util.QueryBuilder.Analyzer
    Lucene.Net.Util.QueryBuilder.EnablePositionIncrements
    QueryBuilder.CreateFieldQuery(Analyzer, Occur, String, String, Boolean, Int32)
    QueryBuilder.NewBooleanQuery(Boolean)
    Lucene.Net.Util.QueryBuilder.NewTermQuery(Lucene.Net.Index.Term)
    Lucene.Net.Util.QueryBuilder.NewPhraseQuery()
    Lucene.Net.Util.QueryBuilder.NewMultiPhraseQuery()
    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)
    System.Object.ToString()
    Namespace: Lucene.Net.QueryParsers.Classic
    Assembly: Lucene.Net.QueryParser.dll
    Syntax
    public class QueryParser : QueryParserBase, ICommonQueryParserConfiguration

    Constructors

    | Improve this Doc View Source

    QueryParser(ICharStream)

    Constructor with user supplied ICharStream.

    Declaration
    protected QueryParser(ICharStream stream)
    Parameters
    Type Name Description
    ICharStream stream
    | Improve this Doc View Source

    QueryParser(QueryParserTokenManager)

    Constructor with generated Token Manager.

    Declaration
    protected QueryParser(QueryParserTokenManager tm)
    Parameters
    Type Name Description
    QueryParserTokenManager tm
    | Improve this Doc View Source

    QueryParser(LuceneVersion, String, Analyzer)

    Constructs a query parser.

    Declaration
    public QueryParser(LuceneVersion matchVersion, string f, Analyzer a)
    Parameters
    Type Name Description
    Lucene.Net.Util.LuceneVersion matchVersion

    Lucene version to match.

    System.String f

    the default field for query terms.

    Lucene.Net.Analysis.Analyzer a

    used to find terms in the query text.

    Properties

    | Improve this Doc View Source

    Jj_nt

    Next token.

    Declaration
    public Token Jj_nt { get; set; }
    Property Value
    Type Description
    Token
    | Improve this Doc View Source

    Token

    Current token.

    Declaration
    public Token Token { get; set; }
    Property Value
    Type Description
    Token
    | Improve this Doc View Source

    TokenSource

    Generated Token Manager.

    Declaration
    public QueryParserTokenManager TokenSource { get; set; }
    Property Value
    Type Description
    QueryParserTokenManager

    Methods

    | Improve this Doc View Source

    Clause(String)

    Declaration
    public Query Clause(string field)
    Parameters
    Type Name Description
    System.String field
    Returns
    Type Description
    Lucene.Net.Search.Query
    | Improve this Doc View Source

    Conjunction()

    Declaration
    public int Conjunction()
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    Disable_tracing()

    Disable tracing.

    Declaration
    public void Disable_tracing()
    | Improve this Doc View Source

    Enable_tracing()

    Enable tracing.

    Declaration
    public void Enable_tracing()
    | Improve this Doc View Source

    GenerateParseException()

    Generate ParseException.

    Declaration
    public virtual ParseException GenerateParseException()
    Returns
    Type Description
    ParseException
    | Improve this Doc View Source

    GetNextToken()

    Get the next Token.

    Declaration
    public Token GetNextToken()
    Returns
    Type Description
    Token
    | Improve this Doc View Source

    GetToken(Int32)

    Get the specific Token.

    Declaration
    public Token GetToken(int index)
    Parameters
    Type Name Description
    System.Int32 index
    Returns
    Type Description
    Token
    | Improve this Doc View Source

    Modifiers()

    Declaration
    public int Modifiers()
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    Query(String)

    Declaration
    public Query Query(string field)
    Parameters
    Type Name Description
    System.String field
    Returns
    Type Description
    Lucene.Net.Search.Query
    | Improve this Doc View Source

    ReInit(ICharStream)

    Reinitialize.

    Declaration
    public override void ReInit(ICharStream stream)
    Parameters
    Type Name Description
    ICharStream stream
    Overrides
    QueryParserBase.ReInit(ICharStream)
    | Improve this Doc View Source

    ReInit(QueryParserTokenManager)

    Reinitialize.

    Declaration
    public virtual void ReInit(QueryParserTokenManager tm)
    Parameters
    Type Name Description
    QueryParserTokenManager tm
    | Improve this Doc View Source

    Term(String)

    Declaration
    public Query Term(string field)
    Parameters
    Type Name Description
    System.String field
    Returns
    Type Description
    Lucene.Net.Search.Query
    | Improve this Doc View Source

    TopLevelQuery(String)

    Declaration
    public sealed override Query TopLevelQuery(string field)
    Parameters
    Type Name Description
    System.String field
    Returns
    Type Description
    Lucene.Net.Search.Query
    Overrides
    QueryParserBase.TopLevelQuery(String)

    Implements

    ICommonQueryParserConfiguration
    • Improve this Doc
    • View Source
    Back to top Copyright © 2022 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.