Show / Hide Table of Contents

    Class MultiTermQuery

    An abstract Query that matches documents containing a subset of terms provided by a FilteredTermsEnum enumeration.

    This query cannot be used directly; you must subclass it and define GetTermsEnum(Terms, AttributeSource) to provide a FilteredTermsEnum that iterates through the terms to be matched.

    NOTE: if MultiTermRewriteMethod is either CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE or SCORING_BOOLEAN_QUERY_REWRITE, you may encounter a BooleanQuery.TooManyClausesException exception during searching, which happens when the number of terms to be searched exceeds MaxClauseCount. Setting MultiTermRewriteMethod to CONSTANT_SCORE_FILTER_REWRITE prevents this.

    The recommended rewrite method is CONSTANT_SCORE_AUTO_REWRITE_DEFAULT: it doesn't spend CPU computing unhelpful scores, and it tries to pick the most performant rewrite method given the query. If you need scoring (like , use MultiTermQuery.TopTermsScoringBooleanQueryRewrite which uses a priority queue to only collect competitive terms and not hit this limitation.

    Note that QueryParsers.Classic.QueryParser produces MultiTermQuerys using CONSTANT_SCORE_AUTO_REWRITE_DEFAULT by default.

    Inheritance
    System.Object
    Query
    MultiTermQuery
    AutomatonQuery
    FuzzyQuery
    NumericRangeQuery<T>
    PrefixQuery
    TermRangeQuery
    Inherited Members
    Query.Boost
    Query.ToString(String)
    Query.ToString()
    Query.CreateWeight(IndexSearcher)
    Query.ExtractTerms(ISet<Term>)
    Query.Clone()
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public abstract class MultiTermQuery : Query

    Constructors

    | Improve this Doc View Source

    MultiTermQuery(String)

    Constructs a query matching terms that cannot be represented with a single Term.

    Declaration
    public MultiTermQuery(string field)
    Parameters
    Type Name Description
    System.String field

    Fields

    | Improve this Doc View Source

    CONSTANT_SCORE_AUTO_REWRITE_DEFAULT

    Read-only default instance of ConstantScoreAutoRewrite, with TermCountCutoff set to DEFAULT_TERM_COUNT_CUTOFF and DocCountPercent set to DEFAULT_DOC_COUNT_PERCENT. Note that you cannot alter the configuration of this instance; you'll need to create a private instance instead.

    Declaration
    public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
    Field Value
    Type Description
    MultiTermQuery.RewriteMethod
    | Improve this Doc View Source

    CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE

    Like SCORING_BOOLEAN_QUERY_REWRITE except scores are not computed. Instead, each matching document receives a constant score equal to the query's boost.

    NOTE: this rewrite method will hit BooleanQuery.TooManyClausesException if the number of terms exceeds MaxClauseCount.

    Declaration
    public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
    Field Value
    Type Description
    MultiTermQuery.RewriteMethod
    See Also
    MultiTermRewriteMethod
    | Improve this Doc View Source

    CONSTANT_SCORE_FILTER_REWRITE

    A rewrite method that first creates a private Filter, by visiting each term in sequence and marking all docs for that term. Matching documents are assigned a constant score equal to the query's boost.

    This method is faster than the BooleanQuery rewrite methods when the number of matched terms or matched documents is non-trivial. Also, it will never hit an errant BooleanQuery.TooManyClausesException exception.

    Declaration
    public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_FILTER_REWRITE
    Field Value
    Type Description
    MultiTermQuery.RewriteMethod
    See Also
    MultiTermRewriteMethod
    | Improve this Doc View Source

    m_field

    Declaration
    protected readonly string m_field
    Field Value
    Type Description
    System.String
    | Improve this Doc View Source

    m_rewriteMethod

    Declaration
    protected MultiTermQuery.RewriteMethod m_rewriteMethod
    Field Value
    Type Description
    MultiTermQuery.RewriteMethod
    | Improve this Doc View Source

    SCORING_BOOLEAN_QUERY_REWRITE

    A rewrite method that first translates each term into SHOULD clause in a BooleanQuery, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost always better to use CONSTANT_SCORE_AUTO_REWRITE_DEFAULT instead.

    NOTE: this rewrite method will hit BooleanQuery.TooManyClausesException if the number of terms exceeds MaxClauseCount.

    Declaration
    public static readonly MultiTermQuery.RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE
    Field Value
    Type Description
    MultiTermQuery.RewriteMethod
    See Also
    MultiTermRewriteMethod

    Properties

    | Improve this Doc View Source

    Field

    Returns the field name for this query

    Declaration
    public string Field { get; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    MultiTermRewriteMethod

    Gets or Sets the rewrite method to be used when executing the query. You can use one of the four core methods, or implement your own subclass of MultiTermQuery.RewriteMethod.

    Declaration
    public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
    Property Value
    Type Description
    MultiTermQuery.RewriteMethod

    Methods

    | Improve this Doc View Source

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    Overrides
    Query.Equals(Object)
    | Improve this Doc View Source

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32
    Overrides
    Query.GetHashCode()
    | Improve this Doc View Source

    GetTermsEnum(Terms)

    Convenience method, if no attributes are needed: this simply passes empty attributes and is equal to:

    GetTermsEnum(terms, new AttributeSource())
    Declaration
    public TermsEnum GetTermsEnum(Terms terms)
    Parameters
    Type Name Description
    Terms terms
    Returns
    Type Description
    TermsEnum
    | Improve this Doc View Source

    GetTermsEnum(Terms, AttributeSource)

    Construct the enumeration to be used, expanding the pattern term. this method should only be called if the field exists (ie, implementations can assume the field does exist). this method should not return null (should instead return EMPTY if no terms match). The TermsEnum must already be positioned to the first matching term. The given AttributeSource is passed by the MultiTermQuery.RewriteMethod to provide attributes, the rewrite method uses to inform about e.g. maximum competitive boosts. this is currently only used by TopTermsRewrite<Q>.

    Declaration
    protected abstract TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
    Parameters
    Type Name Description
    Terms terms
    AttributeSource atts
    Returns
    Type Description
    TermsEnum
    | Improve this Doc View Source

    Rewrite(IndexReader)

    To rewrite to a simpler form, instead return a simpler enum from GetTermsEnum(Terms, AttributeSource). For example, to rewrite to a single term, return a SingleTermsEnum.

    Declaration
    public override sealed Query Rewrite(IndexReader reader)
    Parameters
    Type Name Description
    IndexReader reader
    Returns
    Type Description
    Query
    Overrides
    Query.Rewrite(IndexReader)
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)