Class MultiTermQuery
An abstract Query that matches documents containing a subset of terms provided by a FilteredTermsEnum enumeration.
This query cannot be used directly; you must subclass it and define GetTermsEnum(Terms, AttributeSource) to provide a FilteredTermsEnum that iterates through the terms to be matched.
NOTE: if MultiTermRewriteMethod is either CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE or SCORING_BOOLEAN_QUERY_REWRITE, you may encounter a BooleanQuery.TooManyClausesException exception during searching, which happens when the number of terms to be searched exceeds MaxClauseCount. Setting MultiTermRewriteMethod 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. If you
need scoring (like
Note that QueryParsers.Classic.QueryParser produces MultiTermQuerys using CONSTANT_SCORE_AUTO_REWRITE_DEFAULT by default.
Inherited Members
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class MultiTermQuery : Query
Constructors
Name | Description |
---|---|
MultiTermQuery(String) | Constructs a query matching terms that cannot be represented with a single Term. |
Fields
Name | Description |
---|---|
CONSTANT_SCORE_AUTO_REWRITE_DEFAULT | Read-only default instance of ConstantScoreAutoRewrite, with TermCountCutoff set to DEFAULT_TERM_COUNT_CUTOFF and DocCountPercent set to 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 | 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 BooleanQuery.TooManyClausesException if the number of terms exceeds MaxClauseCount. |
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. 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 BooleanQuery.TooManyClausesException exception. |
m_field | |
m_rewriteMethod | |
SCORING_BOOLEAN_QUERY_REWRITE | A rewrite method that first translates each term into 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.TooManyClausesException if the number of terms exceeds MaxClauseCount. |
Properties
Name | Description |
---|---|
Field | Returns the field name for this query |
MultiTermRewriteMethod | Gets or 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 MultiTermQuery.RewriteMethod. |
Methods
Name | Description |
---|---|
Equals(Object) | |
GetHashCode() | |
GetTermsEnum(Terms) | Convenience method, if no attributes are needed: this simply passes empty attributes and is equal to:
|
GetTermsEnum(Terms, AttributeSource) | Construct the enumeration to be used, expanding the pattern term. this method should only be called if the field exists (ie, implementations can assume the field does exist). this method should not return null (should instead return EMPTY if no terms match). The TermsEnum must already be positioned to the first matching term. The given AttributeSource is passed by the MultiTermQuery.RewriteMethod to provide attributes, the rewrite method uses to inform about e.g. maximum competitive boosts. this is currently only used by TopTermsRewrite<Q>. |
Rewrite(IndexReader) | To rewrite to a simpler form, instead return a simpler enum from GetTermsEnum(Terms, AttributeSource). For example, to rewrite to a single term, return a SingleTermsEnum. |