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

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Lucene::MultiTermQuery Class Referenceabstract

An abstract Query that matches documents containing a subset of terms provided by a {} enumeration. More...

`#include <MultiTermQuery.h>`

Inheritance diagram for Lucene::MultiTermQuery:

## Public Member Functions

| MultiTermQuery ()
virtual | ~MultiTermQuery ()
virtual String | getClassName ()
boost::shared_ptr< MultiTermQuery > | shared_from_this ()
int32_t | getTotalNumberOfTerms ()
| Return the number of unique terms visited during execution of the query. If there are many of them, you may consider using another query type or optimize your total term count in index. More...
void | clearTotalNumberOfTerms ()
| Resets the counting of unique terms. Do this before executing the query/filter. 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 RewriteMethodPtr | getRewriteMethod ()
virtual void | setRewriteMethod (const RewriteMethodPtr &method)
| Sets the rewrite method to be used when executing the query. You can use one of the four core methods, or implement your own subclass of RewriteMethod. 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...
Public Member Functions inherited from Lucene::Query
| Query ()
virtual | ~Query ()
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 | 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...
String | boostString ()
| Return given boost value as a string. More...
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. More...
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects. More...
Public Member Functions inherited from Lucene::LuceneSync
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 RewriteMethodPtr | CONSTANT_SCORE_FILTER_REWRITE ()
| A rewrite method that first creates a private Filter, by visiting each term in sequence and marking all docs for that term. Matching documents are assigned a constant score equal to the query's boost. More...
static RewriteMethodPtr | SCORING_BOOLEAN_QUERY_REWRITE ()
| A rewrite method that first translates each term into BooleanClause.Occur#SHOULD clause in a BooleanQuery, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost always better to use CONSTANT_SCORE_AUTO_REWRITE_DEFAULT instead. More...
static RewriteMethodPtr | CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE ()
| Like SCORING_BOOLEAN_QUERY_REWRITE except scores are not computed. Instead, each matching document receives a constant score equal to the query's boost. More...
static RewriteMethodPtr | CONSTANT_SCORE_AUTO_REWRITE_DEFAULT ()
| Read-only default instance of ConstantScoreAutoRewrite, with {} set to ConstantScoreAutoRewrite#DEFAULT_TERM_COUNT_CUTOFF} and ConstantScoreAutoRewrite#setDocCountPercent} set to { ConstantScoreAutoRewrite#DEFAULT_DOC_COUNT_PERCENT}. Note that you cannot alter the configuration of this instance; you'll need to create a private instance instead. More...
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. More...

## Protected Member Functions

virtual FilteredTermEnumPtr | getEnum (const IndexReaderPtr &reader)=0
| Construct the enumeration to be used, expanding the pattern term. More...
void | incTotalNumberOfTerms (int32_t inc)
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

RewriteMethodPtr | rewriteMethod
int32_t | numberOfTerms
Protected Attributes inherited from Lucene::Query
double | boost
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## Detailed Description

An abstract Query that matches documents containing a subset of terms provided by a {} enumeration.

This query cannot be used directly; you must subclass it and define getEnum to provide a FilteredTermEnum that iterates through the terms to be matched.

NOTE: if setRewriteMethod is either CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE or {}, you may encounter a BooleanQuery.TooManyClauses} exception during searching, which happens when the number of terms to be searched exceeds { BooleanQuery#getMaxClauseCount()}. Setting #setRewriteMethod} to { #CONSTANT_SCORE_FILTER_REWRITE} prevents this. The recommended rewrite method is #CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}: it doesn't spend CPU computing unhelpful scores, and it tries to pick the most performant rewrite method given the query. Note that QueryParser} produces MultiTermQueries using #CONSTANT_SCORE_AUTO_REWRITE_DEFAULT} by default.

## Constructor & Destructor Documentation

## ◆ MultiTermQuery()

Lucene::MultiTermQuery::MultiTermQuery | ( |  | ) |

## ◆ ~MultiTermQuery()

virtual Lucene::MultiTermQuery::~MultiTermQuery | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

static String Lucene::MultiTermQuery::_getClassName | ( |  | ) |

inline static

## ◆ clearTotalNumberOfTerms()

void Lucene::MultiTermQuery::clearTotalNumberOfTerms | ( |  | ) |

Resets the counting of unique terms. Do this before executing the query/filter.

See also
  getTotalNumberOfTerms

## ◆ clone()

virtual LuceneObjectPtr Lucene::MultiTermQuery::clone | ( | const LuceneObjectPtr & | other = `LuceneObjectPtr()` | ) |

virtual

Returns a clone of this query.

Reimplemented from Lucene::Query.

Reimplemented in Lucene::WildcardQuery, Lucene::TermRangeQuery, Lucene::PrefixQuery, Lucene::NumericRangeQuery, and Lucene::FuzzyQuery.

## ◆ CONSTANT_SCORE_AUTO_REWRITE_DEFAULT()

static RewriteMethodPtr Lucene::MultiTermQuery::CONSTANT_SCORE_AUTO_REWRITE_DEFAULT | ( |  | ) |

static

Read-only default instance of ConstantScoreAutoRewrite, with {} set to ConstantScoreAutoRewrite#DEFAULT_TERM_COUNT_CUTOFF} and ConstantScoreAutoRewrite#setDocCountPercent} set to { ConstantScoreAutoRewrite#DEFAULT_DOC_COUNT_PERCENT}. Note that you cannot alter the configuration of this instance; you'll need to create a private instance instead.

## ◆ CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE()

static RewriteMethodPtr Lucene::MultiTermQuery::CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE | ( |  | ) |

static

Like SCORING_BOOLEAN_QUERY_REWRITE except scores are not computed. Instead, each matching document receives a constant score equal to the query's boost.

NOTE: This rewrite method will hit TooManyClauses if the number of terms exceeds {}. #setRewriteMethod

## ◆ CONSTANT_SCORE_FILTER_REWRITE()

static RewriteMethodPtr Lucene::MultiTermQuery::CONSTANT_SCORE_FILTER_REWRITE | ( |  | ) |

static

A rewrite method that first creates a private Filter, by visiting each term in sequence and marking all docs for that term. Matching documents are assigned a constant score equal to the query's boost.

This method is faster than the BooleanQuery rewrite methods when the number of matched terms or matched documents is non-trivial. Also, it will never hit an errant TooManyClauses exception.

See also
  setRewriteMethod

## ◆ equals()

virtual bool Lucene::MultiTermQuery::equals | ( | const LuceneObjectPtr & | other | ) |

virtual

Return whether two objects are equal.

Reimplemented from Lucene::Query.

Reimplemented in Lucene::WildcardQuery, Lucene::TermRangeQuery, Lucene::PrefixQuery, Lucene::NumericRangeQuery, and Lucene::FuzzyQuery.

## ◆ getClassName()

virtual String Lucene::MultiTermQuery::getClassName | ( |  | ) |

inline virtual

Reimplemented from Lucene::Query.

Reimplemented in Lucene::WildcardQuery, Lucene::TermRangeQuery, Lucene::PrefixQuery, Lucene::NumericRangeQuery, and Lucene::FuzzyQuery.

## ◆ getEnum()

virtual FilteredTermEnumPtr Lucene::MultiTermQuery::getEnum | ( | const IndexReaderPtr & | reader | ) |

protected pure virtual

Construct the enumeration to be used, expanding the pattern term.

Implemented in Lucene::WildcardQuery, Lucene::TermRangeQuery, Lucene::PrefixQuery, Lucene::NumericRangeQuery, and Lucene::FuzzyQuery.

## ◆ getRewriteMethod()

virtual RewriteMethodPtr Lucene::MultiTermQuery::getRewriteMethod | ( |  | ) |

virtual

See also
  setRewriteMethod

## ◆ getTotalNumberOfTerms()

int32_t Lucene::MultiTermQuery::getTotalNumberOfTerms | ( |  | ) |

Return the number of unique terms visited during execution of the query. If there are many of them, you may consider using another query type or optimize your total term count in index.

This method is not thread safe, be sure to only call it when no query is running! If you re-use the same query instance for another search, be sure to first reset the term counter with {}. On optimized indexes / no MultiReaders, you get the correct number of unique terms for the whole index. Use this number to compare different queries. For non-optimized indexes this number can also be achieved in non-constant-score mode. In constant-score mode you get the total number of terms seeked for all segments / sub-readers. #clearTotalNumberOfTerms

## ◆ hashCode()

virtual int32_t Lucene::MultiTermQuery::hashCode | ( |  | ) |

virtual

Return hash code for this object.

Reimplemented from Lucene::Query.

Reimplemented in Lucene::WildcardQuery, Lucene::TermRangeQuery, Lucene::PrefixQuery, Lucene::NumericRangeQuery, and Lucene::FuzzyQuery.

## ◆ incTotalNumberOfTerms()

void Lucene::MultiTermQuery::incTotalNumberOfTerms | ( | int32_t | inc | ) |

protected

## ◆ rewrite()

virtual QueryPtr Lucene::MultiTermQuery::rewrite | ( | const IndexReaderPtr & | reader | ) |

virtual

Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.

Reimplemented from Lucene::Query.

Reimplemented in Lucene::WildcardQuery, and Lucene::FuzzyQuery.

## ◆ SCORING_BOOLEAN_QUERY_REWRITE()

static RewriteMethodPtr Lucene::MultiTermQuery::SCORING_BOOLEAN_QUERY_REWRITE | ( |  | ) |

static

A rewrite method that first translates each term into BooleanClause.Occur#SHOULD clause in a BooleanQuery, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost always better to use CONSTANT_SCORE_AUTO_REWRITE_DEFAULT instead.

NOTE: This rewrite method will hit BooleanQuery.TooManyClauses if the number of terms exceeds BooleanQuery#getMaxClauseCount.

See also
  setRewriteMethod

## ◆ setRewriteMethod()

virtual void Lucene::MultiTermQuery::setRewriteMethod | ( | const RewriteMethodPtr & | method | ) |

virtual

Sets the rewrite method to be used when executing the query. You can use one of the four core methods, or implement your own subclass of RewriteMethod.

Reimplemented in Lucene::FuzzyQuery.

## ◆ shared_from_this()

boost::shared_ptr< MultiTermQuery > Lucene::MultiTermQuery::shared_from_this | ( |  | ) |

inline

## Field Documentation

## ◆ numberOfTerms

int32_t Lucene::MultiTermQuery::numberOfTerms

protected

## ◆ rewriteMethod

RewriteMethodPtr Lucene::MultiTermQuery::rewriteMethod

protected

The documentation for this class was generated from the following file:

- MultiTermQuery.h

clucene.sourceforge.net