Show / Hide Table of Contents

    Class DisjunctionMaxQuery

    A query that generates the union of documents produced by its subqueries, and that scores each document with the maximum score for that document as produced by any subquery, plus a tie breaking increment for any additional matching subqueries. This is useful when searching for a word in multiple fields with different boost factors (so that the fields cannot be combined equivalently into a single search field). We want the primary score to be the one associated with the highest boost, not the sum of the field scores (as BooleanQuery would give).

    If the query is "albino elephant" this ensures that "albino" matching one field and "elephant" matching another gets a higher score than "albino" matching both fields.

    To get this result, use both BooleanQuery and DisjunctionMaxQuery: for each term a DisjunctionMaxQuery searches for it in each field, while the set of these DisjunctionMaxQuery's is combined into a BooleanQuery. The tie breaker capability allows results that include the same term in multiple fields to be judged better than results that include this term in only the best of those multiple fields, without confusing this with the better case of two different terms in the multiple fields.

    Collection initializer note: To create and populate a DisjunctionMaxQuery in a single statement, you can use the following example as a guide:

    var disjunctionMaxQuery = new DisjunctionMaxQuery(0.1f) {
        new TermQuery(new Term("field1", "albino")), 
        new TermQuery(new Term("field2", "elephant"))
    };
    Inheritance
    System.Object
    Query
    DisjunctionMaxQuery
    Implements
    IEnumerable<Query>
    Inherited Members
    Query.Boost
    Query.ToString()
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public class DisjunctionMaxQuery : Query, IEnumerable<Query>

    Constructors

    | Improve this Doc View Source

    DisjunctionMaxQuery(ICollection<Query>, Single)

    Creates a new DisjunctionMaxQuery

    Declaration
    public DisjunctionMaxQuery(ICollection<Query> disjuncts, float tieBreakerMultiplier)
    Parameters
    Type Name Description
    ICollection<Query> disjuncts

    A ICollection{Query} of all the disjuncts to add

    System.Single tieBreakerMultiplier

    The weight to give to each matching non-maximum disjunct

    | Improve this Doc View Source

    DisjunctionMaxQuery(Single)

    Creates a new empty DisjunctionMaxQuery. Use Add(Query) to add the subqueries.

    Declaration
    public DisjunctionMaxQuery(float tieBreakerMultiplier)
    Parameters
    Type Name Description
    System.Single tieBreakerMultiplier

    The score of each non-maximum disjunct for a document is multiplied by this weight and added into the final score. If non-zero, the value should be small, on the order of 0.1, which says that 10 occurrences of word in a lower-scored field that is also in a higher scored field is just as good as a unique word in the lower scored field (i.e., one that is not in any higher scored field).

    Properties

    | Improve this Doc View Source

    Disjuncts

    Declaration
    public virtual IList<Query> Disjuncts { get; }
    Property Value
    Type Description
    IList<Query>

    The disjuncts.

    | Improve this Doc View Source

    TieBreakerMultiplier

    Declaration
    public virtual float TieBreakerMultiplier { get; }
    Property Value
    Type Description
    System.Single

    Tie breaker value for multiple matches.

    Methods

    | Improve this Doc View Source

    Add(ICollection<Query>)

    Add a collection of disjuncts to this disjunction via IEnumerable{Query}

    Declaration
    public virtual void Add(ICollection<Query> disjuncts)
    Parameters
    Type Name Description
    ICollection<Query> disjuncts

    A collection of queries to add as disjuncts.

    | Improve this Doc View Source

    Add(Query)

    Add a subquery to this disjunction

    Declaration
    public virtual void Add(Query query)
    Parameters
    Type Name Description
    Query query

    The disjunct added

    | Improve this Doc View Source

    Clone()

    Create a shallow copy of us -- used in rewriting if necessary

    Declaration
    public override object Clone()
    Returns
    Type Description
    System.Object

    A copy of us (but reuse, don't copy, our subqueries)

    Overrides
    Query.Clone()
    | Improve this Doc View Source

    CreateWeight(IndexSearcher)

    Create the Weight used to score us

    Declaration
    public override Weight CreateWeight(IndexSearcher searcher)
    Parameters
    Type Name Description
    IndexSearcher searcher
    Returns
    Type Description
    Weight
    Overrides
    Query.CreateWeight(IndexSearcher)
    | Improve this Doc View Source

    Equals(Object)

    Return true if we represent the same query as o

    Declaration
    public override bool Equals(object o)
    Parameters
    Type Name Description
    System.Object o

    Another object

    Returns
    Type Description
    System.Boolean

    true if o is a DisjunctionMaxQuery with the same boost and the same subqueries, in the same order, as us

    Overrides
    Query.Equals(Object)
    | Improve this Doc View Source

    ExtractTerms(ISet<Term>)

    Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten (Rewrite(IndexReader)) form.

    Declaration
    public override void ExtractTerms(ISet<Term> terms)
    Parameters
    Type Name Description
    ISet<Term> terms
    Overrides
    Query.ExtractTerms(ISet<Term>)
    | Improve this Doc View Source

    GetEnumerator()

    Declaration
    public virtual IEnumerator<Query> GetEnumerator()
    Returns
    Type Description
    IEnumerator<Query>

    An IEnumerator{Query} over the disjuncts

    | Improve this Doc View Source

    GetHashCode()

    Compute a hash code for hashing us

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

    the hash code

    Overrides
    Query.GetHashCode()
    | Improve this Doc View Source

    Rewrite(IndexReader)

    Optimize our representation and our subqueries representations

    Declaration
    public override Query Rewrite(IndexReader reader)
    Parameters
    Type Name Description
    IndexReader reader

    The IndexReader we query

    Returns
    Type Description
    Query

    An optimized copy of us (which may not be a copy if there is nothing to optimize)

    Overrides
    Query.Rewrite(IndexReader)
    | Improve this Doc View Source

    ToString(String)

    Prettyprint us.

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

    The field to which we are applied

    Returns
    Type Description
    System.String

    A string that shows what we do, of the form "(disjunct1 | disjunct2 | ... | disjunctn)^boost"

    Overrides
    Query.ToString(String)

    Implements

    IEnumerable<>
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)