PhraseQuery
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();
*Constructors
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.
Create a phrase query which will match documents that contain the given list of terms at consecutive positions in field.
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.
Create a phrase query which will match documents that contain the given list of terms at consecutive positions in field.