Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class MultiFieldQueryParser

    A QueryParser which constructs queries to search multiple fields.

    Inheritance
    object
    QueryBuilder
    QueryParserBase
    QueryParser
    MultiFieldQueryParser
    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.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>, int, int, Query)
    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.NewRangeQuery(string, string, string, bool, bool)
    QueryParserBase.NewMatchAllDocsQuery()
    QueryParserBase.NewWildcardQuery(Term)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>)
    QueryParserBase.GetBooleanQuery(IList<BooleanClause>, bool)
    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.NewTermQuery(Term)
    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.Classic
    Assembly: Lucene.Net.QueryParser.dll
    Syntax
    public class MultiFieldQueryParser : QueryParser, ICommonQueryParserConfiguration

    Constructors

    MultiFieldQueryParser(LuceneVersion, string[], Analyzer)

    Creates a MultiFieldQueryParser.

    It will, when Parse(string) is called, construct a query like this (assuming the query consists of two terms and you specify the two fields title and body):

    (title:term1 body:term1) (title:term2 body:term2)

    When DefaultOperator is set to AND_OPERATOR, the result will be:

    +(title:term1 body:term1) +(title:term2 body:term2)

    In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.

    Declaration
    public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer)
    Parameters
    Type Name Description
    LuceneVersion matchVersion
    string[] fields
    Analyzer analyzer

    MultiFieldQueryParser(LuceneVersion, string[], Analyzer, IDictionary<string, float>)

    Creates a MultiFieldQueryParser. Allows passing of a map with term to Boost, and the boost to apply to each term.

    It will, when Parse(string) is called, construct a query like this (assuming the query consists of two terms and you specify the two fields title and body):

    (title:term1 body:term1) (title:term2 body:term2)

    When DefaultOperator is set to AND_OPERATOR, the result will be:

    +(title:term1 body:term1) +(title:term2 body:term2)

    When you pass a boost (title=>5 body=>10) you can get

    +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)

    In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.

    Declaration
    public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer, IDictionary<string, float> boosts)
    Parameters
    Type Name Description
    LuceneVersion matchVersion
    string[] fields
    Analyzer analyzer
    IDictionary<string, float> boosts

    Fields

    m_boosts

    A QueryParser which constructs queries to search multiple fields.

    Declaration
    protected IDictionary<string, float> m_boosts
    Field Value
    Type Description
    IDictionary<string, float>

    m_fields

    A QueryParser which constructs queries to search multiple fields.

    Declaration
    protected string[] m_fields
    Field Value
    Type Description
    string[]

    Methods

    GetFieldQuery(string, string, bool)

    A QueryParser which constructs queries to search multiple fields.

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

    throw in overridden method to disallow

    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

    GetPrefixQuery(string, string)

    Factory method for generating a query (similar to GetWildcardQuery(string, string)). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.

    Depending on settings, a 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 wild card queries, which may be necessary due to missing analyzer calls.
    Declaration
    protected override Query GetPrefixQuery(string field, string termStr)
    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

    Returns
    Type Description
    Query

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

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

    throw in overridden method to disallow

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

    A QueryParser which constructs queries to search multiple fields.

    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)

    GetRegexpQuery(string, string)

    Factory method for generating a query. Called when parser parses an input term token that contains a regular expression query.

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

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

    Name of the field query will use.

    string termStr

    Term token that contains a regular expression

    Returns
    Type Description
    Query

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

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

    throw in overridden method to disallow

    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

    Parse(LuceneVersion, string, string[], Occur[], Analyzer)

    Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    string[] fields = {"filename", "contents", "description"};
    Occur[] flags = {Occur.SHOULD,
        Occur.MUST,
        Occur.MUST_NOT};
    MultiFieldQueryParser.Parse("query", fields, flags, analyzer);

    The code above would construct a query:
    (filename:query) +(contents:query) -(description:query)
    Declaration
    public static Query Parse(LuceneVersion matchVersion, string query, string[] fields, Occur[] flags, Analyzer analyzer)
    Parameters
    Type Name Description
    LuceneVersion matchVersion

    Lucene version to match; this is passed through to QueryParser.

    string query

    Query string to parse

    string[] fields

    Fields to search on

    Occur[] flags

    Flags describing the fields

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ParseException

    if query parsing fails

    ArgumentException

    if the length of the fields array differs from the length of the flags array

    Parse(LuceneVersion, string[], string[], Analyzer)

    Parses a query which searches on the fields specified.

    If x fields are specified, this effectively constructs:
    (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
    Declaration
    public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, Analyzer analyzer)
    Parameters
    Type Name Description
    LuceneVersion matchVersion

    Lucene version to match; this is passed through to QueryParser.

    string[] queries

    Queries strings to parse

    string[] fields

    Fields to search on

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ParseException

    if query parsing fails

    ArgumentException

    if the length of the queries array differs from the length of the fields array

    Parse(LuceneVersion, string[], string[], Occur[], Analyzer)

    Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    string[] query = {"query1", "query2", "query3"};
    string[] fields = {"filename", "contents", "description"};
    Occur[] flags = {Occur.SHOULD,
        Occur.MUST,
        Occur.MUST_NOT};
    MultiFieldQueryParser.Parse(query, fields, flags, analyzer);

    The code above would construct a query:
    (filename:query1) +(contents:query2) -(description:query3)
    Declaration
    public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, Occur[] flags, Analyzer analyzer)
    Parameters
    Type Name Description
    LuceneVersion matchVersion

    Lucene version to match; this is passed through to QueryParser.

    string[] queries

    Queries string to parse

    string[] fields

    Fields to search on

    Occur[] flags

    Flags describing the fields

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ParseException

    if query parsing fails

    ArgumentException

    if the length of the queries, fields, and flags array differ

    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.