org.apache.lucene.search

Class PhraseQuery

public class PhraseQuery extends Query

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.

Constructor Summary
PhraseQuery()
Constructs an empty phrase query.
Method Summary
voidadd(Term term)
Adds a term to the end of the query phrase.
voidadd(Term term, int position)
Adds a term to the end of the query phrase.
protected WeightcreateWeight(Searcher searcher)
booleanequals(Object o)
Returns true iff o is equal to this.
voidextractTerms(Set queryTerms)
int[]getPositions()
Returns the relative positions of terms in this phrase.
intgetSlop()
Returns the slop.
Term[]getTerms()
Returns the set of terms in this phrase.
inthashCode()
Returns a hash code value for this object.
voidsetSlop(int s)
Sets the number of other words permitted between words in query phrase.
StringtoString(String f)
Prints a user-readable version of this query.

Constructor Detail

PhraseQuery

public PhraseQuery()
Constructs an empty phrase query.

Method Detail

add

public void add(Term term)
Adds a term to the end of the query phrase. The relative position of the term is the one immediately after the last term added.

add

public void add(Term term, int position)
Adds a term to the end of the query phrase. The relative position of the term within the phrase is specified explicitly. This allows e.g. phrases with more than one term at the same position or phrases with gaps (e.g. in connection with stopwords).

Parameters: term position

createWeight

protected Weight createWeight(Searcher searcher)

equals

public boolean equals(Object o)
Returns true iff o is equal to this.

extractTerms

public void extractTerms(Set queryTerms)

See Also: extractTerms

getPositions

public int[] getPositions()
Returns the relative positions of terms in this phrase.

getSlop

public int getSlop()
Returns the slop. See setSlop().

getTerms

public Term[] getTerms()
Returns the set of terms in this phrase.

hashCode

public int hashCode()
Returns a hash code value for this object.

setSlop

public void setSlop(int s)
Sets the number of other words permitted between words in query phrase. If zero, then this is an exact phrase search. For larger values this works like a WITHIN or NEAR operator.

The slop is in fact an edit-distance, where the units correspond to moves of terms in the query phrase out of position. For example, to switch the order of two words requires two moves (the first move places the words atop one another), so to permit re-orderings of phrases, the slop must be at least two.

More exact matches are scored higher than sloppier matches, thus search results are sorted by exactness.

The slop is zero by default, requiring exact matches.

toString

public String toString(String f)
Prints a user-readable version of this query.
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.