Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class ComplexPhraseQueryParser

    QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".

    Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects

    This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status

    Inheritance
    object
    QueryBuilder
    QueryParserBase
    QueryParser
    ComplexPhraseQueryParser
    Implements
    ICommonQueryParserConfiguration
    Inherited Members
    QueryParser.Conjunction()
    QueryParser.Modifiers()
    QueryParser.TopLevelQuery(string)
    QueryParser.Query(string)
    QueryParser.Clause(string)
    QueryParser.Term(string)
    QueryParser.TokenSource
    QueryParser.Token
    QueryParser.Jj_nt
    QueryParser.ReInit(ICharStream)
    QueryParser.ReInit(QueryParserTokenManager)
    QueryParser.GetNextToken()
    QueryParser.GetToken(int)
    QueryParser.GenerateParseException()
    QueryParser.Enable_tracing()
    QueryParser.Disable_tracing()
    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.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>, int, int, Query)
    QueryParserBase.GetFieldQuery(string, string, bool)
    QueryParserBase.NewFieldQuery(Analyzer, string, string, bool)
    QueryParserBase.NewBooleanClause(Query, Occur)
    QueryParserBase.NewPrefixQuery(Term)
    QueryParserBase.NewRegexpQuery(Term)
    QueryParserBase.NewFuzzyQuery(Term, float, int)
    QueryParserBase.AnalyzeMultitermTerm(string, string, Analyzer)
    QueryParserBase.NewMatchAllDocsQuery()
    QueryParserBase.NewWildcardQuery(Term)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>, bool)
    QueryParserBase.GetRegexpQuery(string, string)
    QueryParserBase.GetPrefixQuery(string, string)
    QueryParserBase.Escape(string)
    QueryBuilder.CreateBooleanQuery(string, string)
    QueryBuilder.CreateBooleanQuery(string, string, Occur)
    QueryBuilder.CreatePhraseQuery(string, string)
    QueryBuilder.CreatePhraseQuery(string, string, int)
    QueryBuilder.CreateMinShouldMatchQuery(string, string, float)
    QueryBuilder.Analyzer
    QueryBuilder.EnablePositionIncrements
    QueryBuilder.CreateFieldQuery(Analyzer, Occur, string, string, bool, int)
    QueryBuilder.NewBooleanQuery(bool)
    QueryBuilder.NewPhraseQuery()
    QueryBuilder.NewMultiPhraseQuery()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.QueryParsers.ComplexPhrase
    Assembly: Lucene.Net.QueryParser.dll
    Syntax
    public class ComplexPhraseQueryParser : QueryParser, ICommonQueryParserConfiguration

    Constructors

    ComplexPhraseQueryParser(LuceneVersion, string, Analyzer)

    QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".

    Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects

    This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status

    Declaration
    public ComplexPhraseQueryParser(LuceneVersion matchVersion, string f, Analyzer a)
    Parameters
    Type Name Description
    LuceneVersion matchVersion
    string f
    Analyzer a

    Properties

    InOrder

    When InOrder is true, the search terms must exists in the documents as the same order as in query. Choose between ordered (true) or un-ordered (false) proximity search.

    Declaration
    public virtual bool InOrder { get; }
    Property Value
    Type Description
    bool

    Methods

    GetFieldQuery(string, string, int)

    Base implementation delegates to GetFieldQuery(string, string, bool). This method may be overridden, for example, to return a Lucene.Net.Search.Spans.SpanNearQuery instead of a Lucene.Net.Search.PhraseQuery.

    Declaration
    protected override Query GetFieldQuery(string field, string queryText, int slop)
    Parameters
    Type Name Description
    string field
    string queryText
    int slop
    Returns
    Type Description
    Query
    Overrides
    QueryParserBase.GetFieldQuery(string, string, int)
    Exceptions
    Type Condition
    ParseException

    throw in overridden method to disallow

    GetFuzzyQuery(string, string, float)

    Factory method for generating a query (similar to GetWildcardQuery(string, string)). Called when parser parses an input term token that has the fuzzy suffix (~) appended.

    Declaration
    protected override Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
    Parameters
    Type Name Description
    string field

    Name of the field query will use.

    string termStr

    Term token to use for building term for the query

    float minSimilarity

    minimum similarity

    Returns
    Type Description
    Query

    Resulting Lucene.Net.Search.Query built for the term

    Overrides
    QueryParserBase.GetFuzzyQuery(string, string, float)
    Exceptions
    Type Condition
    ParseException

    throw in overridden method to disallow

    GetRangeQuery(string, string, string, bool, bool)

    QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".

    Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects

    This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status

    Declaration
    protected override Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
    Parameters
    Type Name Description
    string field
    string part1
    string part2
    bool startInclusive
    bool endInclusive
    Returns
    Type Description
    Query
    Overrides
    QueryParserBase.GetRangeQuery(string, string, string, bool, bool)

    GetWildcardQuery(string, string)

    Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

    Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

    Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.
    Declaration
    protected override Query GetWildcardQuery(string field, string termStr)
    Parameters
    Type Name Description
    string field

    Name of the field query will use.

    string termStr

    Term token that contains one or more wild card characters (? or *), but is not simple prefix term

    Returns
    Type Description
    Query

    Resulting Lucene.Net.Search.Query built for the term

    Overrides
    QueryParserBase.GetWildcardQuery(string, string)
    Exceptions
    Type Condition
    ParseException

    throw in overridden method to disallow

    NewRangeQuery(string, string, string, bool, bool)

    Builds a new Lucene.Net.Search.TermRangeQuery instance

    Declaration
    protected override Query NewRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
    Parameters
    Type Name Description
    string field

    Field

    string part1

    min

    string part2

    max

    bool startInclusive

    true if the start of the range is inclusive

    bool endInclusive

    true if the end of the range is inclusive

    Returns
    Type Description
    Query

    new Lucene.Net.Search.TermRangeQuery instance

    Overrides
    QueryParserBase.NewRangeQuery(string, string, string, bool, bool)

    NewTermQuery(Term)

    Builds a new Lucene.Net.Search.TermQuery instance.

    This is intended for subclasses that wish to customize the generated queries.
    Declaration
    protected override Query NewTermQuery(Term term)
    Parameters
    Type Name Description
    Term term

    Term.

    Returns
    Type Description
    Query

    New Lucene.Net.Search.TermQuery instance.

    Overrides
    Lucene.Net.Util.QueryBuilder.NewTermQuery(Lucene.Net.Index.Term)

    Parse(string)

    Parses a query string, returning a Lucene.Net.Search.Query.

    Declaration
    public override Query Parse(string query)
    Parameters
    Type Name Description
    string query

    the query string to be parsed.

    Returns
    Type Description
    Query
    Overrides
    QueryParserBase.Parse(string)
    Exceptions
    Type Condition
    ParseException

    if the parsing fails

    Implements

    ICommonQueryParserConfiguration
    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.