Forum: Ruby ruby ferret question -> how to get list of values for a give

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B389820ea2e2ee4f166930dea947a303?d=identicon&s=25 didier.prophete (Guest)
on 2005-12-05 10:03
(Received via mailing list)
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(<index dir>)
  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...
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 dbalmain.ml (Guest)
on 2005-12-05 11:57
(Received via mailing list)
On 12/5/05, didier.prophete@gmail.com <didier.prophete@gmail.com> 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
B389820ea2e2ee4f166930dea947a303?d=identicon&s=25 didier.prophete (Guest)
on 2005-12-05 18:14
(Received via mailing list)
Exactly what I needed.
thanks a bunch dave,

-Didier
This topic is locked and can not be replied to.