Methods Summary |
---|
public boolean | equals(java.lang.Object o)Returns true iff o is equal to this.
if (!(o instanceof PrefixQuery))
return false;
PrefixQuery other = (PrefixQuery)o;
return (this.getBoost() == other.getBoost())
&& this.prefix.equals(other.prefix);
|
public org.apache.lucene.index.Term | getPrefix()Returns the prefix of this query. return prefix;
|
public int | hashCode()Returns a hash code value for this object.
return Float.floatToIntBits(getBoost()) ^ prefix.hashCode() ^ 0x6634D93C;
|
public org.apache.lucene.search.Query | rewrite(org.apache.lucene.index.IndexReader reader)
BooleanQuery query = new BooleanQuery(true);
TermEnum enumerator = reader.terms(prefix);
try {
String prefixText = prefix.text();
String prefixField = prefix.field();
do {
Term term = enumerator.term();
if (term != null &&
term.text().startsWith(prefixText) &&
term.field() == prefixField) // interned comparison
{
TermQuery tq = new TermQuery(term); // found a match
tq.setBoost(getBoost()); // set the boost
query.add(tq, BooleanClause.Occur.SHOULD); // add to query
//System.out.println("added " + term);
} else {
break;
}
} while (enumerator.next());
} finally {
enumerator.close();
}
return query;
|
public java.lang.String | toString(java.lang.String field)Prints a user-readable version of this query.
StringBuffer buffer = new StringBuffer();
if (!prefix.field().equals(field)) {
buffer.append(prefix.field());
buffer.append(":");
}
buffer.append(prefix.text());
buffer.append('*");
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
|