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"))
};
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class DisjunctionMaxQuery : Query, IEnumerable<Query>, IEnumerable
Constructors
| Improve this Doc View SourceDisjunctionMaxQuery(ICollection<Query>, Single)
Creates a new DisjunctionMaxQuery
Declaration
public DisjunctionMaxQuery(ICollection<Query> disjuncts, float tieBreakerMultiplier)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.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 |
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 SourceDisjuncts
Declaration
public virtual IList<Query> Disjuncts { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<Query> | The disjuncts. |
TieBreakerMultiplier
Declaration
public virtual float TieBreakerMultiplier { get; }
Property Value
Type | Description |
---|---|
System.Single | Tie breaker value for multiple matches. |
Methods
| Improve this Doc View SourceAdd(Query)
Add a subquery to this disjunction
Declaration
public virtual void Add(Query query)
Parameters
Type | Name | Description |
---|---|---|
Query | query | The disjunct added |
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 |
---|---|---|
System.Collections.Generic.ICollection<Query> | disjuncts | A collection of queries to add as disjuncts. |
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
| Improve this Doc View SourceCreateWeight(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
| Improve this Doc View SourceEquals(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 |
|
Overrides
| Improve this Doc View SourceExtractTerms(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 |
---|---|---|
System.Collections.Generic.ISet<Term> | terms |
Overrides
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If this query is not yet rewritten |
GetEnumerator()
Declaration
public virtual IEnumerator<Query> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<Query> | An IEnumerator{Query} over the disjuncts |
GetHashCode()
Compute a hash code for hashing us
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | the hash code |
Overrides
| Improve this Doc View SourceRewrite(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
| Improve this Doc View SourceToString(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
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |