Forum: Ferret Newbie

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.
4057d36ea1505c263efbdbdc0bf511cd?d=identicon&s=25 D. Krmpotic (rubypassion)
on 2007-03-09 12:20
Hi!


Suppose I have many articles in a database and I want to know how many
times each search term appears in each one of them. Where do I start?

Thank you very much!

David
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2007-03-09 17:09
(Received via mailing list)
On 3/9/07, D. Krmpotic <david.krmpotic@gmail.com> wrote:
> Hi!
>
>
> Suppose I have many articles in a database and I want to know how many
> times each search term appears in each one of them. Where do I start?

Here is an example;

require 'rubygems'
require 'ferret'

index = Ferret::I.new
index << {:content => 'one two three'}
index << {:content => 'no 3 here'}
index << {:content => 'three three three'}

index.reader.term_docs_for(:content, 'three').each do |doc, freq|
  puts "three appeared #{freq} times in document #{doc}"
end
4057d36ea1505c263efbdbdc0bf511cd?d=identicon&s=25 D. Krmpotic (rubypassion)
on 2007-03-11 17:22
Thank you David! that will get me started..
This topic is locked and can not be replied to.