WildcardQuery supports suffix (*something) queries when used through the API (QueryParser does not allow asterisks at the beginning). So I don't think what you've done is necessary... just use a WildcardQuery with a leading asterisk.

There are alternative approaches to this by changing how you index to accommodate suffix queries (reverse what goes in, reverse it and do a prefix query during querying).

        Erik


On Jun 24, 2004, at 11:29 AM, Ben Pryor wrote:

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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to