lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: list all terms in a field
Date Fri, 08 Apr 2005 06:42:13 GMT

: Is there a simple way to list all terms in a field?
: The only approach that I see is to use the IndexReader.terms()  method
: and then iterate over all the results and build my list by manually
: filtering. This seems inefficient and there must be a better way that
: my newbie eyes don't see.

it's the most efficient way i can think of, the trick is in the specifics
of the documentation:

1) TermEnum says...

   Term enumerations are always ordered by Term.compareTo(). Each term in
   the enumeration is greater than all that precede it.

2) Term.compareTo(Term) says...

   The ordering of terms is first by field, then by text.

2) IndexReader.terms(Term) says...

   Returns an enumeration of all terms after a given term.

...which means that if you want all of the Terms for a given field, you
can call IntexReader.terms(new Term("field","")) and get a TermEnum
starting at the very first Term in that field.  you cna then iterate over
the Terms untill you encounter one for a different field (or hit the end
of the TermEnum)

I think that's about as efficient as it gets.

take a look at RangeFilter for an example in use...


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

View raw message