A Query that matches documents containing a particular sequence of terms. A PhraseQuery is built
by QueryParser for input like "new york".
This query may be combined with other terms or queries with a BooleanQuery.
NOTE: All terms in the phrase must match, even those at the same position. If you have
terms at the same position, perhaps synonyms, you probably want MultiPhraseQuery instead
which only requires one term at a position to match.
Also, Leading holes don't have any particular meaning for this query and will be ignored. For
instance this query:
PhraseQuery.Builder builder = new PhraseQuery.Builder();
builder.add(new Term("body", "one"), 4);
builder.add(new Term("body", "two"), 5);
PhraseQuery pq = builder.build();
is equivalent to the below query:
PhraseQuery.Builder builder = new PhraseQuery.Builder();
builder.add(new Term("body", "one"), 0);
builder.add(new Term("body", "two"), 1);
PhraseQuery pq = builder.build();
<init>(int slop, String field, String[] terms)Create a phrase query which will match documents that contain the given list of terms at
consecutive positions in field, and at a maximum edit distance of slop. For
more complicated use-cases, use PhraseQuery.Builder.
<init>(String field, String[] terms)Create a phrase query which will match documents that contain the given list of terms at
consecutive positions in field.
<init>(int slop, String field, org.apache.lucene.util.BytesRef[] terms)Create a phrase query which will match documents that contain the given list of terms at
consecutive positions in field, and at a maximum edit distance of slop. For
more complicated use-cases, use PhraseQuery.Builder.
<init>(String field, org.apache.lucene.util.BytesRef[] terms)Create a phrase query which will match documents that contain the given list of terms at
consecutive positions in field.
termPositionsCost(org.apache.lucene.index.TermsEnum termsEnum)Returns an expected cost in simple operations of processing the occurrences of a term in a
document that contains the term. This is for use by TwoPhaseIterator#matchCost
implementations.
| name | type | description |
|---|---|---|
| terms_enum | org.apache.lucene.index.TermsEnum | The term is the term at which this TermsEnum is positioned. |
createWeight(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost)equals(Object other)Returns true iff o is equal to this.
getField() · also: get_fieldReturns the field this query applies to
hashCode()Returns a hash code value for this object.
getPositions() · also: get_positionsReturns the relative positions of terms in this phrase.
rewrite(org.apache.lucene.search.IndexSearcher indexSearcher)getSlop() · also: get_slopReturn the slop for this PhraseQuery.
The slop is an edit distance between respective positions of terms as defined in this PhraseQuery and the positions of terms in a document.
For instance, when searching for "quick fox", it is expected that the difference
between the positions of fox and quick is 1. So "a quick brown fox"
would be at an edit distance of 1 since the difference of the positions of fox and
quick is 2. Similarly, "the fox is quick" would be at an edit distance of 3
since the difference of the positions of fox and quick is -2. The slop defines
the maximum edit distance for a document to match.
More exact matches are scored higher than sloppier matches, thus search results are sorted by exactness.
toString(String f)Prints a user-readable version of this query.