You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "Paul J. Lucas" <pa...@lucasmail.org> on 2009/03/19 17:41:07 UTC

All the values of a particular field

The Lucene FAQ has a Q, "How do I retrieve all the values of a  
particular field that exists within an index, across all documents?"  
and gives some code.  However, it looks like that code returns only  
unique values.  How does one get all values including duplicates?

- Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: All the values of a particular field

Posted by "Paul J. Lucas" <pa...@lucasmail.org>.
Uhm, a code snippet, perhaps??  Thanks.

- Paul


On Mar 19, 2009, at 10:26 AM, Erick Erickson wrote:

> See TermEnum/TermDocs.....
>
> On Thu, Mar 19, 2009 at 12:41 PM, Paul J. Lucas <pa...@lucasmail.org>  
> wrote:
>
>> The Lucene FAQ has a Q, "How do I retrieve all the values of a  
>> particular
>> field that exists within an index, across all documents?" and gives  
>> some
>> code.  However, it looks like that code returns only unique  
>> values.  How
>> does one get all values including duplicates?

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: All the values of a particular field

Posted by "Paul J. Lucas" <pa...@lucasmail.org>.
Actually, the code I had previously was:

     TermEnum e = reader.terms( new Term( fieldName, "" ) );
     Collection<String> values = new LinkedList<String>();
     while ( fieldName.equals( e.term().field() ) ) {
         String text = e.term().text();
         if ( text.length() > 0 )
             values.add( text );
         if ( !e.next() )
             break;
     }

I think all I have to do is repeat the add() when docFreq() > 1 like:

         if ( text.length() > 0 )
             for ( int i = e.docFreq(); i > 0; --i )
                 values.add( text );

Right?

- Paul


On Mar 19, 2009, at 10:26 AM, Erick Erickson wrote:

> See TermEnum/TermDocs.....
>
> On Thu, Mar 19, 2009 at 12:41 PM, Paul J. Lucas <pa...@lucasmail.org>  
> wrote:
>
>> The Lucene FAQ has a Q, "How do I retrieve all the values of a  
>> particular
>> field that exists within an index, across all documents?" and gives  
>> some
>> code.  However, it looks like that code returns only unique  
>> values.  How
>> does one get all values including duplicates?

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: All the values of a particular field

Posted by Erick Erickson <er...@gmail.com>.
See TermEnum/TermDocs.....

On Thu, Mar 19, 2009 at 12:41 PM, Paul J. Lucas <pa...@lucasmail.org> wrote:

> The Lucene FAQ has a Q, "How do I retrieve all the values of a particular
> field that exists within an index, across all documents?" and gives some
> code.  However, it looks like that code returns only unique values.  How
> does one get all values including duplicates?
>
> - Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>