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 (likeInheritance
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public abstract class MultiTermQuery : Query
Constructors
MultiTermQuery(string)
Constructs a query matching terms that cannot be represented with a single Term.
Declaration
protected MultiTermQuery(string field)
Parameters
Type | Name | Description |
---|---|---|
string | field |
Fields
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.
Declaration
public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
Field Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
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.Declaration
public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
Field Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
See Also
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.Declaration
public static readonly MultiTermQuery.RewriteMethod CONSTANT_SCORE_FILTER_REWRITE
Field Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
See Also
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.Declaration
public static readonly MultiTermQuery.RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE
Field Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
See Also
m_field
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 (likeDeclaration
protected readonly string m_field
Field Value
Type | Description |
---|---|
string |
m_rewriteMethod
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 (likeDeclaration
protected MultiTermQuery.RewriteMethod m_rewriteMethod
Field Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
Properties
Field
Returns the field name for this query
Declaration
public string Field { get; }
Property Value
Type | Description |
---|---|
string |
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.
Declaration
public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
Property Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
Methods
Equals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
GetTermsEnum(Terms)
Convenience method, if no attributes are needed: this simply passes empty attributes and is equal to:
GetTermsEnum(terms, new AttributeSource())
Declaration
public TermsEnum GetTermsEnum(Terms terms)
Parameters
Type | Name | Description |
---|---|---|
Terms | terms |
Returns
Type | Description |
---|---|
TermsEnum |
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>.
Declaration
protected abstract TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
Parameters
Type | Name | Description |
---|---|---|
Terms | terms | |
AttributeSource | atts |
Returns
Type | Description |
---|---|
TermsEnum |
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.
Declaration
public override sealed Query Rewrite(IndexReader reader)
Parameters
Type | Name | Description |
---|---|---|
IndexReader | reader |
Returns
Type | Description |
---|---|
Query |