# Ruby ferret question -\> how to get list of values for a give

**URL:** <https://www.ruby-forum.com/t/ruby-ferret-question-how-to-get-list-of-values-for-a-give/49483>\
**Category:** Ruby\
**Created:** [December 5, 2005, 10:03am UTC](https://www.ruby-forum.com/t/ruby-ferret-question-how-to-get-list-of-values-for-a-give/49483 "2005-12-05T10:03:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![didier.prophete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@didier.prophete](https://www.ruby-forum.com/u/didier.prophete)\
**Post date:** [December 5, 2005, 10:03am UTC](https://www.ruby-forum.com/t/ruby-ferret-question-how-to-get-list-of-values-for-a-give/49483/1 "2005-12-05T10:03:19Z")

</div>

hi all,

So I have a ferret question. Suppose I have a bunch of documents I  
indexed using ferret. For the sake of simplicity, all my documents have  
basically 1 relevant field: “city”, which I set up during indexing.

So my question is: how do I get all the different values for ‘city’ ?  
(without having to go through every single document).

There’s got to be something that can tell me all the different cities  
used in all my document, like [‘NY’, ‘SF’, ‘LA’] (assuming all my  
documents are either in LA, SF or NY)

Thanks for your help

-Didier

ps: I know that I can already get the list of ‘field names’ using:  
reader = Index::IndexReader.open()  
p reader.get\_field\_names  
but I can’t seem to find the missing link to get to the list of values  
for a given term…

---

<div class="post-metadata">

**Author:** ![didier.prophete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@didier.prophete](https://www.ruby-forum.com/u/didier.prophete)\
**Post date:** [December 5, 2005, 11:57am UTC](https://www.ruby-forum.com/t/ruby-ferret-question-how-to-get-list-of-values-for-a-give/49483/2 "2005-12-05T11:57:32Z")

</div>

On 12/5/05, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> used in all my document, like [‘NY’, ‘SF’, ‘LA’] (assuming all my  
> documents are either in LA, SF or NY)

Hi Didier,

Something like this. I don’t have time to test it but it should be  
pretty close.

```
reader = Index::IndexReader.open(<index dir>)
term_enum = reader.terms_from(Term.new("city", ""));
cities = []
while (term_enum.term.field == "city")
    cities << term_enum.term.text
    break if not term_enum.next?
end

```

Cheers,  
Dave

---

<div class="post-metadata">

**Author:** ![didier.prophete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@didier.prophete](https://www.ruby-forum.com/u/didier.prophete)\
**Post date:** [December 5, 2005, 6:14pm UTC](https://www.ruby-forum.com/t/ruby-ferret-question-how-to-get-list-of-values-for-a-give/49483/3 "2005-12-05T18:14:46Z")

</div>

Exactly what I needed.  
thanks a bunch dave,

-Didier
