Class MultiTermQuery

java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.MultiTermQuery
Direct Known Subclasses:
AutomatonQuery, FuzzyQuery, TermsQuery

public abstract class MultiTermQuery extends Query
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 MultiTermQuery.RewriteMethod is either CONSTANT_SCORE_BOOLEAN_REWRITE or SCORING_BOOLEAN_REWRITE, you may encounter a IndexSearcher.TooManyClauses exception during searching, which happens when the number of terms to be searched exceeds IndexSearcher.getMaxClauseCount(). Setting MultiTermQuery.RewriteMethod to CONSTANT_SCORE_REWRITE prevents this.

The recommended rewrite method is CONSTANT_SCORE_REWRITE: it doesn't spend CPU computing unhelpful scores, and is the most performant rewrite method given the query. If you need scoring (like FuzzyQuery, use MultiTermQuery.TopTermsScoringBooleanQueryRewrite which uses a priority queue to only collect competitive terms and not hit this limitation.

Note that org.apache.lucene.queryparser.classic.QueryParser produces MultiTermQueries using CONSTANT_SCORE_REWRITE by default.