Hi,
I have read up on the negative aspects of a SuffixQuery class. Be these as
they may, a situation came up where one is required for an application I'm
working on, so I started with the PrefixQuery class and modified it to match
suffixes instead. The relevant method that changed was the rewrite() method:
public Query rewrite(IndexReader reader) throws IOException
{
BooleanQuery query = new BooleanQuery();
Term startTerm = new Term(suffix.field(), "");
TermEnum enumerator = reader.terms(startTerm);
try
{
String suffixText = suffix.text();
String suffixField = suffix.field();
do
{
Term term = enumerator.term();
if (term != null && term.field() != suffixField)
{
break;
}
if (term != null &&
term.text().endsWith(suffixText))
{
TermQuery tq = new TermQuery(term); //
found a match
tq.setBoost(getBoost()); // set
the boost
query.add(tq, false, false); //
add to query
}
}
while (enumerator.next());
}
finally
{
enumerator.close();
}
return query;
}
Questions: How na�ve is this implementation? How bad will performance be on
a large index, and is there a more efficient way to do this?
Thanks for advice,
Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]