Class TermInSetQuery

All Implemented Interfaces:
Accountable

public class TermInSetQuery extends MultiTermQuery implements Accountable
Specialization for a disjunction over many terms that, by default, behaves like a ConstantScoreQuery over a BooleanQuery containing only BooleanClause.Occur.SHOULD clauses.

For instance in the following example, both q1 and q2 would yield the same scores:

 Query q1 = new TermInSetQuery("field", new BytesRef("foo"), new BytesRef("bar"));

 BooleanQuery bq = new BooleanQuery();
 bq.add(new TermQuery(new Term("field", "foo")), Occur.SHOULD);
 bq.add(new TermQuery(new Term("field", "bar")), Occur.SHOULD);
 Query q2 = new ConstantScoreQuery(bq);
 

Unless a custom MultiTermQuery.RewriteMethod is provided, this query executes like a regular disjunction where there are few terms. However, when there are many terms, instead of merging iterators on the fly, it will populate a bit set with matching docs for the least-costly terms and maintain a size-limited set of more costly iterators that are merged on the fly. For more details, see MultiTermQuery.CONSTANT_SCORE_BLENDED_REWRITE.

Users may also provide a custom MultiTermQuery.RewriteMethod to define different execution behavior, such as relying on doc values (see: MultiTermQuery.DOC_VALUES_REWRITE), or if scores are required (see: MultiTermQuery.SCORING_BOOLEAN_REWRITE). See MultiTermQuery documentation for more rewrite options.

NOTE: This query produces scores that are equal to its boost