lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Seltzer" <>
Subject PrefixQuery.rewrite
Date Fri, 17 Apr 2009 19:18:38 GMT

I'm writing a small function to enumerate all the values of a field. I
decided that I'd base my code of the PrefixQuery.rewrite() code. This
code, as I understand it, is designed to expand a prefix wildcard and
rewrite the query as a long boolean series of ANDs.

To improve performance the code has a Break statement designed to kick
out of the TermEnum starts enumerating on another field.

  //FROM /src/java/org/apache/lucene/search/
  public Query rewrite(IndexReader reader) throws IOException {
    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 {
      } while (;
    } finally {
    return query;

I think that there may be a logic problem here - - - to me it seems that
if I performed a prefix query on a Field that wasn't first in line
during the the TermEnum's output that my prefix would never be expanded.
I may be misunderstanding the ordering that IndexReader.terms(Term)

This seems like a pretty serious issue, which is why I think there is
some error in my understanding of the Enumeration process. Can anyone
correct me?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message