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)
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.createWeight(searcher);
}
return new PhrasePrefixWeight(searcher);
|
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 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();
buffer.append(terms[0].text() + (terms.length > 1 ? "*" : ""));
if (i.hasNext())
buffer.append(" ");
}
buffer.append("\"");
if (slop != 0) {
buffer.append("~");
buffer.append(slop);
}
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
|