Methods Summary |
---|
public void | add(org.apache.lucene.index.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.
int position = 0;
if(positions.size() > 0)
position = ((Integer) positions.lastElement()).intValue() + 1;
add(term, position);
|
public void | add(org.apache.lucene.index.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).
if (terms.size() == 0)
field = term.field();
else if (term.field() != field)
throw new IllegalArgumentException("All phrase terms must be in the same field: " + term);
terms.addElement(term);
positions.addElement(new Integer(position));
|
protected org.apache.lucene.search.Weight | createWeight(org.apache.lucene.search.Searcher searcher)
if (terms.size() == 1) { // optimize one-term case
Term term = (Term)terms.elementAt(0);
Query termQuery = new TermQuery(term);
termQuery.setBoost(getBoost());
return termQuery.createWeight(searcher);
}
return new PhraseWeight(searcher);
|
public boolean | equals(java.lang.Object o)Returns true iff o is equal to this.
if (!(o instanceof PhraseQuery))
return false;
PhraseQuery other = (PhraseQuery)o;
return (this.getBoost() == other.getBoost())
&& (this.slop == other.slop)
&& this.terms.equals(other.terms)
&& this.positions.equals(other.positions);
|
public void | extractTerms(java.util.Set queryTerms)
queryTerms.addAll(terms);
|
public int[] | getPositions()Returns the relative positions of terms in this phrase.
int[] result = new int[positions.size()];
for(int i = 0; i < positions.size(); i++)
result[i] = ((Integer) positions.elementAt(i)).intValue();
return result;
|
public int | getSlop()Returns the slop. See setSlop(). return slop;
|
public org.apache.lucene.index.Term[] | getTerms()Returns the set of terms in this phrase.
return (Term[])terms.toArray(new Term[0]);
|
public int | hashCode()Returns a hash code value for this object.
return Float.floatToIntBits(getBoost())
^ slop
^ terms.hashCode()
^ positions.hashCode();
|
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. slop = s;
|
public java.lang.String | toString(java.lang.String f)Prints a user-readable version of this query.
StringBuffer buffer = new StringBuffer();
if (!field.equals(f)) {
buffer.append(field);
buffer.append(":");
}
buffer.append("\"");
for (int i = 0; i < terms.size(); i++) {
buffer.append(((Term)terms.elementAt(i)).text());
if (i != terms.size()-1)
buffer.append(" ");
}
buffer.append("\"");
if (slop != 0) {
buffer.append("~");
buffer.append(slop);
}
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
|