Hello,

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/PrefixQuery.java
  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 {
          break;
        }
      } while (enumerator.next());
    } finally {
      enumerator.close();
    }
    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)
produces. 

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?

Thanks!

-Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-dev-h...@lucene.apache.org

Reply via email to