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.
More...
#include <DisjunctionMaxQuery.h>
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.
◆ DisjunctionMaxQuery() [1/2]
Lucene::DisjunctionMaxQuery::DisjunctionMaxQuery |
( |
double |
tieBreakerMultiplier = 0.0 | ) |
|
Creates a new empty DisjunctionMaxQuery. Use add() to add the subqueries.
- Parameters
-
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 (ie., one that is not in any higher scored field. |
◆ DisjunctionMaxQuery() [2/2]
Lucene::DisjunctionMaxQuery::DisjunctionMaxQuery |
( |
Collection< QueryPtr > |
disjuncts, |
|
|
double |
tieBreakerMultiplier |
|
) |
| |
◆ ~DisjunctionMaxQuery()
virtual Lucene::DisjunctionMaxQuery::~DisjunctionMaxQuery |
( |
| ) |
|
|
virtual |
◆ _getClassName()
static String Lucene::DisjunctionMaxQuery::_getClassName |
( |
| ) |
|
|
inlinestatic |
◆ add() [1/2]
Add a collection of disjuncts to this disjunction.
◆ add() [2/2]
void Lucene::DisjunctionMaxQuery::add |
( |
const QueryPtr & |
query | ) |
|
Add a subquery to this disjunction.
- Parameters
-
◆ begin()
An iterator over the disjuncts.
◆ clone()
Create a shallow copy of us - used in rewriting if necessary.
- Returns
- a copy of us (but reuse, don't copy, our subqueries)
Reimplemented from Lucene::Query.
◆ createWeight()
◆ end()
◆ equals()
virtual bool Lucene::DisjunctionMaxQuery::equals |
( |
const LuceneObjectPtr & |
other | ) |
|
|
virtual |
◆ extractTerms()
virtual void Lucene::DisjunctionMaxQuery::extractTerms |
( |
SetTerm |
terms | ) |
|
|
virtual |
Adds all terms occurring in this query to the terms set.
Reimplemented from Lucene::Query.
◆ getClassName()
virtual String Lucene::DisjunctionMaxQuery::getClassName |
( |
| ) |
|
|
inlinevirtual |
◆ hashCode()
virtual int32_t Lucene::DisjunctionMaxQuery::hashCode |
( |
| ) |
|
|
virtual |
Return hash code for this object.
Reimplemented from Lucene::Query.
◆ rewrite()
Optimize our representation and our subqueries representations.
- Parameters
-
- Returns
- an optimized copy of us (which may not be a copy if there is nothing to optimize)
Reimplemented from Lucene::Query.
◆ shared_from_this()
◆ toString() [1/3]
virtual String Lucene::Query::toString |
( |
| ) |
|
|
virtual |
◆ toString() [2/3]
virtual String Lucene::Query::toString |
( |
const String & |
field | ) |
|
|
virtual |
Prints a query to a string, with field assumed to be the default field and omitted.
The representation used is one that is supposed to be readable by QueryParser
. However, there are the following limitations:
If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
Some of the more complicated queries (eg. span queries) don't have a representation that can be parsed by QueryParser.
Reimplemented from Lucene::Query.
◆ toString() [3/3]
virtual String Lucene::DisjunctionMaxQuery::toString |
( |
const String & |
field | ) |
|
|
virtual |
Pretty print us.
- Parameters
-
field | the field to which we are applied |
- Returns
- a string that shows what we do, of the form "(disjunct1 | disjunct2 | ... | disjunctn)^boost"
Reimplemented from Lucene::Query.
◆ disjuncts
◆ tieBreakerMultiplier
double Lucene::DisjunctionMaxQuery::tieBreakerMultiplier |
|
protected |
Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking.
The documentation for this class was generated from the following file: