Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes
Lucene::DisjunctionMaxQuery Class Reference

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>

+ Inheritance diagram for Lucene::DisjunctionMaxQuery:

Public Member Functions

 DisjunctionMaxQuery (double tieBreakerMultiplier=0.0)
 Creates a new empty DisjunctionMaxQuery. Use add() to add the subqueries.
 
 DisjunctionMaxQuery (Collection< QueryPtr > disjuncts, double tieBreakerMultiplier)
 Creates a new DisjunctionMaxQuery.
 
virtual ~DisjunctionMaxQuery ()
 
virtual String getClassName ()
 
boost::shared_ptr< DisjunctionMaxQueryshared_from_this ()
 
void add (const QueryPtr &query)
 Add a subquery to this disjunction.
 
void add (Collection< QueryPtr > disjuncts)
 Add a collection of disjuncts to this disjunction.
 
Collection< QueryPtr >::iterator begin ()
 An iterator over the disjuncts.
 
Collection< QueryPtr >::iterator end ()
 
virtual WeightPtr createWeight (const SearcherPtr &searcher)
 Create the Weight used to score us.
 
virtual QueryPtr rewrite (const IndexReaderPtr &reader)
 Optimize our representation and our subqueries representations.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Create a shallow copy of us - used in rewriting if necessary.
 
virtual void extractTerms (SetTerm terms)
 Adds all terms occurring in this query to the terms set.
 
virtual String toString (const String &field)
 Pretty print us.
 
virtual bool equals (const LuceneObjectPtr &other)
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual String toString (const String &field)
 Prints a query to a string, with field assumed to be the default field and omitted.
 
virtual String toString ()
 Prints a query to a string.
 
- Public Member Functions inherited from Lucene::Query
 Query ()
 
virtual ~Query ()
 
boost::shared_ptr< Queryshared_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.
 
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.
 
virtual WeightPtr weight (const SearcherPtr &searcher)
 Constructs and initializes a Weight for a top-level query.
 
virtual QueryPtr combine (Collection< QueryPtr > queries)
 Called when re-writing queries under MultiSearcher.
 
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.
 
String boostString ()
 Return given boost value as a string.
 
- Public Member Functions inherited from Lucene::LuceneObject
virtual ~LuceneObject ()
 
virtual void initialize ()
 Called directly after instantiation to create objects that depend on this object being fully constructed.
 
virtual int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
- Public Member Functions inherited from Lucene::LuceneSync
virtual ~LuceneSync ()
 
virtual SynchronizePtr getSync ()
 Return this object synchronize lock.
 
virtual LuceneSignalPtr getSignal ()
 Return this object signal.
 
virtual void lock (int32_t timeout=0)
 Lock this object using an optional timeout.
 
virtual void unlock ()
 Unlock this object.
 
virtual bool holdsLock ()
 Returns true if this object is currently locked by current thread.
 
virtual void wait (int32_t timeout=0)
 Wait for signal using an optional timeout.
 
virtual void notifyAll ()
 Notify all threads waiting for signal.
 

Static Public Member Functions

static String _getClassName ()
 
- Static Public Member Functions inherited from Lucene::Query
static String _getClassName ()
 
static QueryPtr mergeBooleanQueries (Collection< BooleanQueryPtr > queries)
 Merges the clauses of a set of BooleanQuery's into a single BooleanQuery.
 

Protected Attributes

Collection< QueryPtrdisjuncts
 The subqueries.
 
double tieBreakerMultiplier
 Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking.
 
- Protected Attributes inherited from Lucene::Query
double boost
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Additional Inherited Members

- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DisjunctionMaxQuery() [1/2]

Lucene::DisjunctionMaxQuery::DisjunctionMaxQuery ( double  tieBreakerMultiplier = 0.0)

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

Parameters
tieBreakerMultiplierthe 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 
)

Creates a new DisjunctionMaxQuery.

Parameters
disjunctsA Collection<QueryPtr> of all the disjuncts to add
tieBreakerMultiplierThe weight to give to each matching non-maximum disjunct

◆ ~DisjunctionMaxQuery()

virtual Lucene::DisjunctionMaxQuery::~DisjunctionMaxQuery ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::DisjunctionMaxQuery::_getClassName ( )
inlinestatic

◆ add() [1/2]

void Lucene::DisjunctionMaxQuery::add ( Collection< QueryPtr disjuncts)

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
querythe disjunct added

◆ begin()

Collection< QueryPtr >::iterator Lucene::DisjunctionMaxQuery::begin ( )

An iterator over the disjuncts.

◆ clone()

virtual LuceneObjectPtr Lucene::DisjunctionMaxQuery::clone ( const LuceneObjectPtr other = LuceneObjectPtr())
virtual

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()

virtual WeightPtr Lucene::DisjunctionMaxQuery::createWeight ( const SearcherPtr searcher)
virtual

Create the Weight used to score us.

Reimplemented from Lucene::Query.

◆ end()

Collection< QueryPtr >::iterator Lucene::DisjunctionMaxQuery::end ( )

◆ equals()

virtual bool Lucene::DisjunctionMaxQuery::equals ( const LuceneObjectPtr other)
virtual
Returns
true if other is a DisjunctionMaxQuery with the same boost and the same subqueries, in the same order, as us

Reimplemented from Lucene::Query.

◆ 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

Reimplemented from Lucene::Query.

◆ hashCode()

virtual int32_t Lucene::DisjunctionMaxQuery::hashCode ( )
virtual

Return hash code for this object.

Reimplemented from Lucene::Query.

◆ rewrite()

virtual QueryPtr Lucene::DisjunctionMaxQuery::rewrite ( const IndexReaderPtr reader)
virtual

Optimize our representation and our subqueries representations.

Parameters
readerthe IndexReader we query
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()

boost::shared_ptr< DisjunctionMaxQuery > Lucene::DisjunctionMaxQuery::shared_from_this ( )
inline

◆ toString() [1/3]

virtual String Lucene::Query::toString ( )
virtual

Prints a query to a string.

Reimplemented from Lucene::Query.

◆ 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
fieldthe 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.

Field Documentation

◆ disjuncts

Collection<QueryPtr> Lucene::DisjunctionMaxQuery::disjuncts
protected

The subqueries.

◆ 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:

clucene.sourceforge.net