public class TermsQuery extends Query implements Accountable
ConstantScoreQuery
over a BooleanQuery
containing only
BooleanClause.Occur.SHOULD
clauses.
For instance in the following example, both @{code q1} and q2
would yield the same scores:
Query q1 = new TermsQuery(new Term("field", "foo"), new Term("field", "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);
When there are few terms, this query executes like a regular disjunction.
However, when there are many terms, instead of merging iterators on the fly,
it will populate a bit set with matching docs and return a Scorer
over this bit set.
NOTE: This query produces scores that are equal to its boost
Constructor and Description |
---|
TermsQuery(Collection<Term> terms)
Creates a new
TermsQuery from the given collection. |
TermsQuery(String field,
BytesRef... terms)
Creates a new
TermsQuery from the given BytesRef array for
a single field. |
TermsQuery(String field,
Collection<BytesRef> terms)
Creates a new
TermsQuery from the given collection for
a single field. |
TermsQuery(Term... terms)
Creates a new
TermsQuery from the given array. |
Modifier and Type | Method and Description |
---|---|
Weight |
createWeight(IndexSearcher searcher,
boolean needsScores) |
boolean |
equals(Object other) |
Collection<Accountable> |
getChildResources() |
PrefixCodedTerms |
getTermData()
Returns the terms wrapped in a PrefixCodedTerms.
|
int |
hashCode() |
long |
ramBytesUsed() |
Query |
rewrite(IndexReader reader) |
String |
toString(String defaultField) |
classHash, sameClassAs, toString
public TermsQuery(Collection<Term> terms)
TermsQuery
from the given collection. It
can contain duplicate terms and multiple fields.public TermsQuery(String field, Collection<BytesRef> terms)
TermsQuery
from the given collection for
a single field. It can contain duplicate terms.public TermsQuery(String field, BytesRef... terms)
TermsQuery
from the given BytesRef
array for
a single field.public TermsQuery(Term... terms)
TermsQuery
from the given array. The array can
contain duplicate terms and multiple fields.public Query rewrite(IndexReader reader) throws IOException
rewrite
in class Query
IOException
public PrefixCodedTerms getTermData()
public long ramBytesUsed()
ramBytesUsed
in interface Accountable
public Collection<Accountable> getChildResources()
getChildResources
in interface Accountable
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException
createWeight
in class Query
IOException
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.