public abstract class MultiNodeTermQuery extends NodePrimitiveQuery
NodePrimitiveQuery
that matches documents
containing a subset of terms provided by a FilteredTermEnum
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: since CONSTANT_SCORE_FILTER_REWRITE
is deactivated
in SIREn, the setRewriteMethod(org.sindice.siren.search.node.MultiNodeTermQuery.RewriteMethod)
will always be either
CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
or SCORING_BOOLEAN_QUERY_REWRITE
. Therefore, you may encounter a
NodeBooleanQuery.TooManyClauses
exception during
searching, which happens when the number of terms to be
searched exceeds NodeBooleanQuery.getMaxClauseCount()
.
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 NodeFuzzyQuery
, use
TopTermsScoringNodeBooleanQueryRewrite
which uses
a priority queue to only collect competitive terms
and not hit this limitation.
Note that QueryParser
produces
SirenMultiTermQueries using CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
by
default.
Code taken from MultiTermQuery
and adapted for SIREn.
Modifier and Type | Class and Description |
---|---|
static class |
MultiNodeTermQuery.RewriteMethod
Abstract class that defines how the query is rewritten.
|
Modifier and Type | Field and Description |
---|---|
static MultiNodeTermQuery.RewriteMethod |
CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
Read-only default instance of
NodeConstantScoreAutoRewrite , with NodeConstantScoreAutoRewrite.setTermCountCutoff(int) set to
NodeConstantScoreAutoRewrite.DEFAULT_TERM_COUNT_CUTOFF
and NodeConstantScoreAutoRewrite.setDocCountPercent(double) set to
NodeConstantScoreAutoRewrite.DEFAULT_DOC_COUNT_PERCENT . |
static MultiNodeTermQuery.RewriteMethod |
CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
Like
SCORING_BOOLEAN_QUERY_REWRITE except
scores are not computed. |
static MultiNodeTermQuery.RewriteMethod |
CONSTANT_SCORE_FILTER_REWRITE
Rewrite method currently deactivated in SIREn.
|
protected String |
field |
protected MultiNodeTermQuery.RewriteMethod |
rewriteMethod |
static MultiNodeTermQuery.RewriteMethod |
SCORING_BOOLEAN_QUERY_REWRITE
A rewrite method that first translates each term into
NodeBooleanClause.Occur.SHOULD clause in a
SirenBooleanQuery, and keeps the scores as computed by the
query. |
datatype
ancestor, levelConstraint, lowerBound, upperBound
Constructor and Description |
---|
MultiNodeTermQuery(String field)
Constructs a query matching terms that cannot be represented with a single
Term.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
String |
getField()
Returns the field name for this query
|
MultiNodeTermQuery.RewriteMethod |
getRewriteMethod() |
protected org.apache.lucene.index.TermsEnum |
getTermsEnum(org.apache.lucene.index.Terms terms)
Convenience method, if no attributes are needed:
This simply passes empty attributes and is equal to:
getTermsEnum(terms, new AttributeSource()) |
protected abstract org.apache.lucene.index.TermsEnum |
getTermsEnum(org.apache.lucene.index.Terms terms,
org.apache.lucene.util.AttributeSource atts)
Construct the enumeration to be used, expanding the
pattern term.
|
int |
hashCode() |
org.apache.lucene.search.Query |
rewrite(org.apache.lucene.index.IndexReader reader) |
void |
setRewriteMethod(MultiNodeTermQuery.RewriteMethod method)
Sets the rewrite method to be used when executing the
query.
|
setDatatype, wrapToStringWithDatatype
getDocsNodesAndPositionsEnum, getLevelConstraint, getNodeConstraint, setAncestorPointer, setLevelConstraint, setNodeConstraint, setNodeConstraint
protected final String field
protected MultiNodeTermQuery.RewriteMethod rewriteMethod
public static final MultiNodeTermQuery.RewriteMethod 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 NodeBooleanQuery.TooManyClauses
exception.
public static final MultiNodeTermQuery.RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE
NodeBooleanClause.Occur.SHOULD
clause in a
SirenBooleanQuery, 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 NodeBooleanQuery.TooManyClauses
if the number of terms
exceeds NodeBooleanQuery.getMaxClauseCount()
.
public static final MultiNodeTermQuery.RewriteMethod CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
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 NodeBooleanQuery.TooManyClauses
if the number of terms
exceeds NodeBooleanQuery.getMaxClauseCount()
.
public static final MultiNodeTermQuery.RewriteMethod CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
NodeConstantScoreAutoRewrite
, with NodeConstantScoreAutoRewrite.setTermCountCutoff(int)
set to
NodeConstantScoreAutoRewrite.DEFAULT_TERM_COUNT_CUTOFF
and NodeConstantScoreAutoRewrite.setDocCountPercent(double)
set to
NodeConstantScoreAutoRewrite.DEFAULT_DOC_COUNT_PERCENT
.
Note that you cannot alter the configuration of this
instance; you'll need to create a private instance
instead.public MultiNodeTermQuery(String field)
public final String getField()
protected abstract org.apache.lucene.index.TermsEnum getTermsEnum(org.apache.lucene.index.Terms terms, org.apache.lucene.util.AttributeSource atts) throws IOException
TermsEnum.EMPTY
if no
terms match). The TermsEnum must already be
positioned to the first matching term.
The given AttributeSource
is passed by the MultiNodeTermQuery.RewriteMethod
to
provide attributes, the rewrite method uses to inform about e.g. maximum competitive boosts.
This is currently only used by TopNodeTermsRewrite
IOException
protected final org.apache.lucene.index.TermsEnum getTermsEnum(org.apache.lucene.index.Terms terms) throws IOException
getTermsEnum(terms, new AttributeSource())
IOException
public org.apache.lucene.search.Query rewrite(org.apache.lucene.index.IndexReader reader) throws IOException
rewrite
in class org.apache.lucene.search.Query
IOException
public MultiNodeTermQuery.RewriteMethod getRewriteMethod()
public void setRewriteMethod(MultiNodeTermQuery.RewriteMethod method)
MultiNodeTermQuery.RewriteMethod
.public int hashCode()
hashCode
in class org.apache.lucene.search.Query
public boolean equals(Object obj)
equals
in class org.apache.lucene.search.Query
Copyright © 2014. All rights reserved.