ruby ferret question -> how to get list of values for a given term ?

  • Thread starter didier.prophete
  • Start date
D

didier.prophete

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...
 
D

David Balmain

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)

Hi Didier,

Something like this. I don't have time to test it but it should be pretty c=
lose.

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

Cheers,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top