Lucene++ - a full-featured, c++ search engine
API Documentation
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>
Public Member Functions | |
DisjunctionMaxQuery (double tieBreakerMultiplier=0.0) | |
Creates a new empty DisjunctionMaxQuery. Use add() to add the subqueries. More... | |
DisjunctionMaxQuery (Collection< QueryPtr > disjuncts, double tieBreakerMultiplier) | |
Creates a new DisjunctionMaxQuery. More... | |
virtual | ~DisjunctionMaxQuery () |
virtual String | getClassName () |
boost::shared_ptr< DisjunctionMaxQuery > | shared_from_this () |
void | add (const QueryPtr &query) |
Add a subquery to this disjunction. More... | |
void | add (Collection< QueryPtr > disjuncts) |
Add a collection of disjuncts to this disjunction. More... | |
Collection< QueryPtr >::iterator | begin () |
An iterator over the disjuncts. More... | |
Collection< QueryPtr >::iterator | end () |
virtual WeightPtr | createWeight (const SearcherPtr &searcher) |
Create the Weight used to score us. More... | |
virtual QueryPtr | rewrite (const IndexReaderPtr &reader) |
Optimize our representation and our subqueries representations. More... | |
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
Create a shallow copy of us - used in rewriting if necessary. More... | |
virtual void | extractTerms (SetTerm terms) |
Adds all terms occurring in this query to the terms set. More... | |
virtual String | toString (const String &field) |
Pretty print us. More... | |
virtual bool | equals (const LuceneObjectPtr &other) |
virtual int32_t | hashCode () |
Return hash code for this object. More... | |
virtual String | toString (const String &field) |
Prints a query to a string, with field assumed to be the default field and omitted. More... | |
virtual String | toString () |
Prints a query to a string. More... | |
![]() | |
Query () | |
virtual | ~Query () |
virtual String | getClassName () |
boost::shared_ptr< Query > | shared_from_this () |
virtual void | setBoost (double b) |
Sets the boost for this query clause to b. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. More... | |
virtual double | getBoost () |
Gets the boost for this clause. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default. More... | |
virtual String | toString (const String &field) |
Prints a query to a string, with field assumed to be the default field and omitted. More... | |
virtual String | toString () |
Prints a query to a string. More... | |
virtual WeightPtr | createWeight (const SearcherPtr &searcher) |
Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves. More... | |
virtual WeightPtr | weight (const SearcherPtr &searcher) |
Constructs and initializes a Weight for a top-level query. More... | |
virtual QueryPtr | rewrite (const IndexReaderPtr &reader) |
Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys. More... | |
virtual QueryPtr | combine (Collection< QueryPtr > queries) |
Called when re-writing queries under MultiSearcher. More... | |
virtual void | extractTerms (SetTerm terms) |
Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form. More... | |
virtual SimilarityPtr | getSimilarity (const SearcherPtr &searcher) |
Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned. More... | |
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
Returns a clone of this query. More... | |
virtual int32_t | hashCode () |
Return hash code for this object. More... | |
virtual bool | equals (const LuceneObjectPtr &other) |
Return whether two objects are equal. More... | |
String | boostString () |
Return given boost value as a string. More... | |
![]() | |
virtual | ~LuceneObject () |
virtual void | initialize () |
Called directly after instantiation to create objects that depend on this object being fully constructed. More... | |
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
Return clone of this object. More... | |
virtual int32_t | hashCode () |
Return hash code for this object. More... | |
virtual bool | equals (const LuceneObjectPtr &other) |
Return whether two objects are equal. More... | |
virtual int32_t | compareTo (const LuceneObjectPtr &other) |
Compare two objects. More... | |
virtual String | toString () |
Returns a string representation of the object. More... | |
![]() | |
virtual | ~LuceneSync () |
virtual SynchronizePtr | getSync () |
Return this object synchronize lock. More... | |
virtual LuceneSignalPtr | getSignal () |
Return this object signal. More... | |
virtual void | lock (int32_t timeout=0) |
Lock this object using an optional timeout. More... | |
virtual void | unlock () |
Unlock this object. More... | |
virtual bool | holdsLock () |
Returns true if this object is currently locked by current thread. More... | |
virtual void | wait (int32_t timeout=0) |
Wait for signal using an optional timeout. More... | |
virtual void | notifyAll () |
Notify all threads waiting for signal. More... | |
Static Public Member Functions | |
static String | _getClassName () |
![]() | |
static String | _getClassName () |
static QueryPtr | mergeBooleanQueries (Collection< BooleanQueryPtr > queries) |
Merges the clauses of a set of BooleanQuery's into a single BooleanQuery. More... | |
Protected Attributes | |
Collection< QueryPtr > | disjuncts |
The subqueries. More... | |
double | tieBreakerMultiplier |
Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking. More... | |
![]() | |
double | boost |
![]() | |
SynchronizePtr | objectLock |
LuceneSignalPtr | objectSignal |
Additional Inherited Members | |
![]() | |
LuceneObject () | |
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.
Lucene::DisjunctionMaxQuery::DisjunctionMaxQuery | ( | double | tieBreakerMultiplier = 0.0 | ) |
Creates a new empty DisjunctionMaxQuery. Use add() to add the subqueries.
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. |
Lucene::DisjunctionMaxQuery::DisjunctionMaxQuery | ( | Collection< QueryPtr > | disjuncts, |
double | tieBreakerMultiplier | ||
) |
Creates a new DisjunctionMaxQuery.
disjuncts | A Collection<QueryPtr> of all the disjuncts to add |
tieBreakerMultiplier | The weight to give to each matching non-maximum disjunct |
|
virtual |
|
inlinestatic |
void Lucene::DisjunctionMaxQuery::add | ( | Collection< QueryPtr > | disjuncts | ) |
Add a collection of disjuncts to this disjunction.
void Lucene::DisjunctionMaxQuery::add | ( | const QueryPtr & | query | ) |
Add a subquery to this disjunction.
query | the disjunct added |
Collection< QueryPtr >::iterator Lucene::DisjunctionMaxQuery::begin | ( | ) |
An iterator over the disjuncts.
|
virtual |
Create a shallow copy of us - used in rewriting if necessary.
Reimplemented from Lucene::Query.
|
virtual |
Create the Weight used to score us.
Reimplemented from Lucene::Query.
Collection< QueryPtr >::iterator Lucene::DisjunctionMaxQuery::end | ( | ) |
|
virtual |
Reimplemented from Lucene::Query.
|
virtual |
Adds all terms occurring in this query to the terms set.
Reimplemented from Lucene::Query.
|
inlinevirtual |
Reimplemented from Lucene::Query.
|
virtual |
Return hash code for this object.
Reimplemented from Lucene::Query.
|
virtual |
Optimize our representation and our subqueries representations.
reader | the IndexReader we query |
Reimplemented from Lucene::Query.
|
inline |
|
virtual |
Prints a query to a string.
Reimplemented from Lucene::Query.
|
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.
|
virtual |
Pretty print us.
field | the field to which we are applied |
Reimplemented from Lucene::Query.
|
protected |
The subqueries.
|
protected |
Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking.