public class PhraseWildcardQuery extends Query
PhraseQuery
, built with one or more MultiTermQuery
that provides term expansions for multi-terms (one of the expanded terms must match).
Its main advantage is to control the total number of expansions across all MultiTermQuery
and across all segments.
Use the PhraseWildcardQuery.Builder
to build a PhraseWildcardQuery
.
This query is similar to MultiPhraseQuery
, but it handles, controls and optimizes the
multi-term expansions.
This query is equivalent to building an ordered SpanNearQuery
with a list of SpanTermQuery
and
SpanMultiTermQueryWrapper
.
But it optimizes the multi-term expansions and the segment accesses.
It first resolves the single-terms to early stop if some does not match. Then
it expands each multi-term sequentially, stopping immediately if one does not
match. It detects the segments that do not match to skip them for the next
expansions. This often avoid expanding the other multi-terms on some or
even all segments. And finally it controls the total number of expansions.
Immutable.
Modifier and Type | Class and Description |
---|---|
static class |
PhraseWildcardQuery.Builder
Builds a
PhraseWildcardQuery . |
protected static class |
PhraseWildcardQuery.MultiTerm
Phrase term with expansions.
|
protected static class |
PhraseWildcardQuery.PhraseTerm
All
PhraseWildcardQuery.PhraseTerm are light and immutable. |
protected class |
PhraseWildcardQuery.SegmentTermsSizeComparator
Compares segments based of the number of terms they contain.
|
protected static class |
PhraseWildcardQuery.SingleTerm
Phrase term with no expansion.
|
static class |
PhraseWildcardQuery.TermBytesTermState
Holds a pair of term bytes - term state.
|
protected static class |
PhraseWildcardQuery.TermData
|
protected static class |
PhraseWildcardQuery.TermsData
Holds the
TermState and TermStatistics for all the matched
and collected Term , for all phrase terms, for all segments. |
static class |
PhraseWildcardQuery.TermStats
Accumulates the doc freq and total term freq.
|
protected static class |
PhraseWildcardQuery.TestCounters
Test counters incremented when assertions are enabled.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
field |
protected int |
maxMultiTermExpansions |
protected static Query |
NO_MATCH_QUERY |
protected java.util.List<PhraseWildcardQuery.PhraseTerm> |
phraseTerms |
protected boolean |
segmentOptimizationEnabled |
protected int |
slop |
Modifier | Constructor and Description |
---|---|
protected |
PhraseWildcardQuery(java.lang.String field,
java.util.List<PhraseWildcardQuery.PhraseTerm> phraseTerms,
int slop,
int maxMultiTermExpansions,
boolean segmentOptimizationEnabled) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkTermsHavePositions(Terms terms) |
protected int |
collectMultiTermData(PhraseWildcardQuery.MultiTerm multiTerm,
IndexSearcher searcher,
java.util.List<LeafReaderContext> segments,
int remainingMultiTerms,
int maxExpansionsForTerm,
PhraseWildcardQuery.TermsData termsData)
Collects the
TermState and TermStatistics for a multi-term
with expansion. |
protected java.util.List<PhraseWildcardQuery.TermBytesTermState> |
collectMultiTermDataForSegment(PhraseWildcardQuery.MultiTerm multiTerm,
LeafReaderContext leafReaderContext,
int remainingExpansions,
MutableValueBool shouldStopSegmentIteration,
java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> termStatsMap)
Collects the
TermState list and TermStatistics for a multi-term
on a specific index segment. |
protected void |
collectMultiTermStats(IndexSearcher searcher,
java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> termStatsMap,
PhraseWildcardQuery.TermsData termsData,
PhraseWildcardQuery.TermData termData)
Collect the term stats across all segments.
|
protected int |
collectSingleTermData(PhraseWildcardQuery.SingleTerm singleTerm,
IndexSearcher searcher,
java.util.List<LeafReaderContext> segments,
PhraseWildcardQuery.TermsData termsData)
Collects the
TermState and TermStatistics for a single-term
without expansion. |
(package private) PhraseWeight |
createPhraseWeight(IndexSearcher searcher,
ScoreMode scoreMode,
float boost,
PhraseWildcardQuery.TermsData termsData) |
protected PhraseWildcardQuery.TermsData |
createTermsData(int numSegments)
Creates new
PhraseWildcardQuery.TermsData . |
protected TermsEnum |
createTermsEnum(PhraseWildcardQuery.MultiTerm multiTerm,
LeafReaderContext leafReaderContext)
Creates the
TermsEnum for the given PhraseWildcardQuery.MultiTerm and segment. |
protected java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> |
createTermStatsMap(PhraseWildcardQuery.MultiTerm multiTerm)
Creates a
PhraseWildcardQuery.TermStats map for a PhraseWildcardQuery.MultiTerm . |
Weight |
createWeight(IndexSearcher searcher,
ScoreMode scoreMode,
float boost)
Expert: Constructs an appropriate Weight implementation for this query.
|
protected Weight |
earlyStopWeight() |
boolean |
equals(java.lang.Object o)
Override and implement query instance equivalence properly in a subclass.
|
java.lang.String |
getField() |
int |
hashCode()
Override and implement query hash code properly in a subclass.
|
protected Weight |
noMatchWeight() |
Query |
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
|
protected boolean |
shouldOptimizeSegments() |
java.lang.String |
toString(java.lang.String omittedField)
Prints a query to a string, with
field assumed to be the
default field and omitted. |
void |
visit(QueryVisitor visitor)
Recurse through the query tree, visiting any child queries
|
classHash, sameClassAs, toString
protected static final Query NO_MATCH_QUERY
protected final java.lang.String field
protected final java.util.List<PhraseWildcardQuery.PhraseTerm> phraseTerms
protected final int slop
protected final int maxMultiTermExpansions
protected final boolean segmentOptimizationEnabled
protected PhraseWildcardQuery(java.lang.String field, java.util.List<PhraseWildcardQuery.PhraseTerm> phraseTerms, int slop, int maxMultiTermExpansions, boolean segmentOptimizationEnabled)
public java.lang.String getField()
public Query rewrite(IndexReader reader) throws java.io.IOException
Query
public void visit(QueryVisitor visitor)
Query
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws java.io.IOException
Query
Only implemented by primitive queries, which re-write to themselves.
createWeight
in class Query
scoreMode
- How the produced scorers will be consumed.boost
- The boost that is propagated by the parent queries.java.io.IOException
protected PhraseWildcardQuery.TermsData createTermsData(int numSegments)
PhraseWildcardQuery.TermsData
.protected Weight earlyStopWeight()
protected Weight noMatchWeight()
PhraseWeight createPhraseWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost, PhraseWildcardQuery.TermsData termsData) throws java.io.IOException
java.io.IOException
public boolean equals(java.lang.Object o)
Query
QueryCache
works properly.
Typically a query will be equal to another only if it's an instance of
the same class and its document-filtering properties are identical that other
instance. Utility methods are provided for certain repetitive code.equals
in class Query
Query.sameClassAs(Object)
,
Query.classHash()
public int hashCode()
Query
QueryCache
works properly.hashCode
in class Query
Query.equals(Object)
public final java.lang.String toString(java.lang.String omittedField)
Query
field
assumed to be the
default field and omitted.protected int collectSingleTermData(PhraseWildcardQuery.SingleTerm singleTerm, IndexSearcher searcher, java.util.List<LeafReaderContext> segments, PhraseWildcardQuery.TermsData termsData) throws java.io.IOException
TermState
and TermStatistics
for a single-term
without expansion.termsData
- receives the collected data.java.io.IOException
protected int collectMultiTermData(PhraseWildcardQuery.MultiTerm multiTerm, IndexSearcher searcher, java.util.List<LeafReaderContext> segments, int remainingMultiTerms, int maxExpansionsForTerm, PhraseWildcardQuery.TermsData termsData) throws java.io.IOException
TermState
and TermStatistics
for a multi-term
with expansion.remainingMultiTerms
- the number of remaining multi-terms to process,
including the current one, excluding the multi-terms already processed.termsData
- receives the collected data.java.io.IOException
protected boolean shouldOptimizeSegments()
protected java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> createTermStatsMap(PhraseWildcardQuery.MultiTerm multiTerm)
PhraseWildcardQuery.TermStats
map for a PhraseWildcardQuery.MultiTerm
.protected java.util.List<PhraseWildcardQuery.TermBytesTermState> collectMultiTermDataForSegment(PhraseWildcardQuery.MultiTerm multiTerm, LeafReaderContext leafReaderContext, int remainingExpansions, MutableValueBool shouldStopSegmentIteration, java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> termStatsMap) throws java.io.IOException
TermState
list and TermStatistics
for a multi-term
on a specific index segment.remainingExpansions
- the number of remaining expansions allowed
for the segment.shouldStopSegmentIteration
- to be set to true to stop the segment
iteration calling this method repeatedly.termStatsMap
- receives the collected PhraseWildcardQuery.TermStats
across all segments.java.io.IOException
protected TermsEnum createTermsEnum(PhraseWildcardQuery.MultiTerm multiTerm, LeafReaderContext leafReaderContext) throws java.io.IOException
TermsEnum
for the given PhraseWildcardQuery.MultiTerm
and segment.java.io.IOException
protected void collectMultiTermStats(IndexSearcher searcher, java.util.Map<BytesRef,PhraseWildcardQuery.TermStats> termStatsMap, PhraseWildcardQuery.TermsData termsData, PhraseWildcardQuery.TermData termData) throws java.io.IOException
termStatsMap
- input map of already collected PhraseWildcardQuery.TermStats
.termsData
- receives the TermStatistics
computed for all PhraseWildcardQuery.TermStats
.termData
- receives all the collected Term
.java.io.IOException
protected void checkTermsHavePositions(Terms terms)