public class MultiPhraseQuery extends Query
PhraseQuery, with the possibility of
adding more than one term at the same position that are treated as a disjunction (OR).
To use this class to search for the phrase "Microsoft app*" first create a Builder and use
MultiPhraseQuery.Builder.add(Term) on the term "microsoft" (assuming lowercase analysis), then
find all terms that have "app" as prefix using LeafReader.terms(String),
seeking to "app" then iterating and collecting terms until there is no longer
that prefix, and finally use MultiPhraseQuery.Builder.add(Term[]) to add them.
MultiPhraseQuery.Builder.build() returns the fully constructed (and immutable) MultiPhraseQuery.| Modifier and Type | Class and Description |
|---|---|
static class |
MultiPhraseQuery.Builder
A builder for multi-phrase queries
|
private class |
MultiPhraseQuery.MultiPhraseWeight |
(package private) static class |
MultiPhraseQuery.UnionPostingsEnum
Takes the logical union of multiple PostingsEnum iterators.
|
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
field |
private int[] |
positions |
private int |
slop |
private Term[][] |
termArrays |
| Modifier | Constructor and Description |
|---|---|
private |
MultiPhraseQuery(java.lang.String field,
Term[][] termArrays,
int[] positions,
int slop) |
| Modifier and Type | Method and Description |
|---|---|
Weight |
createWeight(IndexSearcher searcher,
boolean needsScores)
Expert: Constructs an appropriate Weight implementation for this query.
|
boolean |
equals(java.lang.Object other)
Returns true if
o is equal to this. |
private boolean |
equalsTo(MultiPhraseQuery other) |
int[] |
getPositions()
Returns the relative positions of terms in this phrase.
|
int |
getSlop()
Sets the phrase slop for this query.
|
Term[][] |
getTermArrays()
Returns the arrays of arrays of terms in the multi-phrase.
|
int |
hashCode()
Returns a hash code value for this object.
|
Query |
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
|
private boolean |
termArraysEquals(Term[][] termArrays1,
Term[][] termArrays2) |
private int |
termArraysHashCode() |
java.lang.String |
toString(java.lang.String f)
Prints a user-readable version of this query.
|
classHash, sameClassAs, toStringprivate final java.lang.String field
private final Term[][] termArrays
private final int[] positions
private final int slop
private MultiPhraseQuery(java.lang.String field,
Term[][] termArrays,
int[] positions,
int slop)
public int getSlop()
PhraseQuery.getSlop()public Term[][] getTermArrays()
public int[] getPositions()
public Query rewrite(IndexReader reader) throws java.io.IOException
Querypublic Weight createWeight(IndexSearcher searcher, boolean needsScores) throws java.io.IOException
QueryOnly implemented by primitive queries, which re-write to themselves.
createWeight in class QueryneedsScores - True if document scores (Scorer.score()) or match
frequencies (Scorer.freq()) are needed.java.io.IOExceptionpublic final java.lang.String toString(java.lang.String f)
public boolean equals(java.lang.Object other)
o is equal to this.equals in class QueryQuery.sameClassAs(Object),
Query.classHash()private boolean equalsTo(MultiPhraseQuery other)
public int hashCode()
hashCode in class QueryQuery.equals(Object)private int termArraysHashCode()