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

Link copied to clipboard
constructor(slop: Int, field: String, vararg terms: String?)

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.

constructor(field: String, vararg terms: String?)

Create a phrase query which will match documents that contain the given list of terms at consecutive positions in field.

constructor(slop: Int, field: String, vararg terms: BytesRef?)

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.

constructor(field: String, vararg terms: BytesRef?)

Create a phrase query which will match documents that contain the given list of terms at consecutive positions in field.

Types

Link copied to clipboard
class Builder

A builder for phrase queries.

Link copied to clipboard
object Companion
Link copied to clipboard

Term postings and position information for phrase matching

Properties

Link copied to clipboard

Returns the field this query applies to

Link copied to clipboard

Returns the relative positions of terms in this phrase.

Link copied to clipboard
val slop: Int

Return the slop for this PhraseQuery.

Link copied to clipboard

Functions

Link copied to clipboard
open override fun createWeight(searcher: IndexSearcher, scoreMode: ScoreMode, boost: Float): Weight

Expert: Constructs an appropriate Weight implementation for this query.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Returns true iff o is equal to this.

Link copied to clipboard
open override fun hashCode(): Int

Returns a hash code value for this object.

Link copied to clipboard
open override fun rewrite(indexSearcher: IndexSearcher): Query

Returns the list of terms in this phrase.

Link copied to clipboard
open override fun toString(f: String?): String

Prints a user-readable version of this query.

open override fun toString(): String

Prints a query to a string.

Link copied to clipboard
open override fun visit(visitor: QueryVisitor)

Recurse through the query tree, visiting any child queries.