Methods Summary |
---|
public void | add(org.apache.lucene.index.Term term)Add a single term at the next position in the phrase. add(new Term[]{term});
|
public void | add(org.apache.lucene.index.Term[] terms)Add multiple terms at the next position in the phrase. Any of the terms
may match.
int position = 0;
if (positions.size() > 0)
position = ((Integer) positions.lastElement()).intValue() + 1;
add(terms, position);
|
public void | add(org.apache.lucene.index.Term[] terms, int position)Allows to specify the relative position of terms within the phrase.
if (termArrays.size() == 0)
field = terms[0].field();
for (int i = 0; i < terms.length; i++) {
if (terms[i].field() != field) {
throw new IllegalArgumentException(
"All phrase terms must be in the same field (" + field + "): "
+ terms[i]);
}
}
termArrays.add(terms);
positions.addElement(new Integer(position));
|
protected org.apache.lucene.search.Weight | createWeight(org.apache.lucene.search.Searcher searcher)
return new MultiPhraseWeight(searcher);
|
public boolean | equals(java.lang.Object o)Returns true if o is equal to this.
if (!(o instanceof MultiPhraseQuery)) return false;
MultiPhraseQuery other = (MultiPhraseQuery)o;
return this.getBoost() == other.getBoost()
&& this.slop == other.slop
&& this.termArrays.equals(other.termArrays)
&& this.positions.equals(other.positions);
|
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()Sets the phrase slop for this query. return slop;
|
public int | hashCode()Returns a hash code value for this object.
return Float.floatToIntBits(getBoost())
^ slop
^ termArrays.hashCode()
^ positions.hashCode()
^ 0x4AC65113;
|
public org.apache.lucene.search.Query | rewrite(org.apache.lucene.index.IndexReader reader)
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanQuery boq = new BooleanQuery(true);
for (int i=0; i<terms.length; i++) {
boq.add(new TermQuery(terms[i]), BooleanClause.Occur.SHOULD);
}
boq.setBoost(getBoost());
return boq;
} else {
return this;
}
|
public void | setSlop(int s)Sets the phrase slop for this query.
slop = s;
|
public final 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("\"");
Iterator i = termArrays.iterator();
while (i.hasNext()) {
Term[] terms = (Term[])i.next();
if (terms.length > 1) {
buffer.append("(");
for (int j = 0; j < terms.length; j++) {
buffer.append(terms[j].text());
if (j < terms.length-1)
buffer.append(" ");
}
buffer.append(")");
} else {
buffer.append(terms[0].text());
}
if (i.hasNext())
buffer.append(" ");
}
buffer.append("\"");
if (slop != 0) {
buffer.append("~");
buffer.append(slop);
}
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
|