lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <li...@ehatchersolutions.com>
Subject Re: How to obtain unique field values
Date Mon, 30 Dec 2002 19:17:04 GMT
Perfect!  Many thanks.

	Erik


On Monday, December 30, 2002, at 12:54  PM, Doug Cutting wrote:

> 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 (!terms.next())
>       break;
>   }
> } finally {
>   terms.close();
> }
>
> Doug
>
>
> --
> To unsubscribe, e-mail:   
> <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:lucene-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message