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
DisjunctionMaxQuery(ICollection<Query>, float)
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 |
float | tieBreakerMultiplier | The weight to give to each matching non-maximum disjunct |
DisjunctionMaxQuery(float)
Creates a new empty DisjunctionMaxQuery. Use Add(Query) to add the subqueries.
Declaration
public DisjunctionMaxQuery(float tieBreakerMultiplier)
Parameters
Type | Name | Description |
---|---|---|
float | 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
Disjuncts
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"))
};
Declaration
public virtual IList<Query> Disjuncts { get; }
Property Value
Type | Description |
---|---|
IList<Query> | The disjuncts. |
TieBreakerMultiplier
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"))
};
Declaration
public virtual float TieBreakerMultiplier { get; }
Property Value
Type | Description |
---|---|
float | Tie breaker value for multiple matches. |
Methods
Add(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}
NOTE: When overriding this method, be aware that the constructor of this class calls a private method and not this virtual method. So if you need to override the behavior during the initialization, call your own private method from the constructor with whatever custom behavior you need.
Declaration
public virtual void Add(ICollection<Query> disjuncts)
Parameters
Type | Name | Description |
---|---|---|
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 |
---|---|
object | A copy of us (but reuse, don't copy, our subqueries) |
Overrides
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
Equals(object)
Return true
if we represent the same query as o
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | Another object |
Returns
Type | Description |
---|---|
bool |
|
Overrides
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
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If this query is not yet rewritten |
GetEnumerator()
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"))
};
Declaration
public virtual IEnumerator<Query> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Query> | An IEnumerator{Query} over the disjuncts |
GetHashCode()
Compute a hash code for hashing us
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | the hash code |
Overrides
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
ToString(string)
Prettyprint us.
Declaration
public override string ToString(string field)
Parameters
Type | Name | Description |
---|---|---|
string | field | The field to which we are applied |
Returns
Type | Description |
---|---|
string | A string that shows what we do, of the form "(disjunct1 | disjunct2 | ... | disjunctn)^boost" |