lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Pryor <BPr...@widen.com>
Subject Suffix query
Date Thu, 24 Jun 2004 15:29:26 GMT
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: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message