public class NGramPhraseQuery extends Query
PhraseQuery which is optimized for n-gram phrase query.
For example, when you query "ABCD" on a 2-gram field, you may want to use
NGramPhraseQuery rather than PhraseQuery, because NGramPhraseQuery
will rewrite(IndexReader) the query to "AB/0 CD/2", while PhraseQuery
will query "AB/0 BC/1 CD/2" (where term/position).| Modifier and Type | Field and Description |
|---|---|
private int |
n |
private PhraseQuery |
phraseQuery |
| Constructor and Description |
|---|
NGramPhraseQuery(int n,
PhraseQuery query)
Constructor that takes gram size.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object other)
Override and implement query instance equivalence properly in a subclass.
|
private boolean |
equalsTo(NGramPhraseQuery other) |
int |
getN()
Return the n in n-gram
|
int[] |
getPositions()
Return the list of relative positions that each term should appear at.
|
Term[] |
getTerms()
Return the list of terms.
|
int |
hashCode()
Override and implement query hash code properly in a subclass.
|
Query |
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
|
java.lang.String |
toString(java.lang.String field)
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, createWeight, sameClassAs, toStringprivate final int n
private final PhraseQuery phraseQuery
public NGramPhraseQuery(int n,
PhraseQuery query)
n - n-gram sizepublic Query rewrite(IndexReader reader) throws java.io.IOException
Querypublic void visit(QueryVisitor visitor)
Querypublic boolean equals(java.lang.Object other)
QueryQueryCache 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 QueryQuery.sameClassAs(Object),
Query.classHash()private boolean equalsTo(NGramPhraseQuery other)
public int hashCode()
QueryQueryCache works properly.hashCode in class QueryQuery.equals(Object)public int getN()
public Term[] getTerms()
public int[] getPositions()