lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <>
Subject Re: How to obtain unique field values
Date Mon, 30 Dec 2002 17:54:27 GMT
Erik Hatcher wrote:
> Is it possible for me to retrieve all the values of a particular field 
> that exists within an index, across all documents?
> For example, I'm indexing documents that have a "category" associated 
> with them.  Several documents will share the same category.  I'd like to 
> be able to retrieve all categories.

The trick is to enumerate terms with that field.  Terms are sorted first 
by field, then by text, so all terms with a given field are adjacent in 
enumerations.  Term enumeration is also efficient.

try {
   TermEnum terms = indexReader.terms(new Term("category", ""));
   while ("category".equals(enum.term().field())) {

     ... collect enum.term().text() ...

     if (!
} finally {


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

View raw message