Forum: Ferret Creating my own analyzer

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.
Pedro =?ISO-8859-1?Q?C=F4rte-Real?= (Guest)
on 2006-04-20 19:27
(Received via mailing list)
I created this analyzer:

class DescriptionAnalyzer < Ferret::Analysis::Analyzer
  def token_stream(field, string)
    if field == "code"
      return CodeTokenStream.new(string)
    else
      return Ferret::Analysis::Analyzer.new.token_stream(field,string)
    end
  end
end

and created an IndexWriter with it:

Ferret::Index::IndexWriter.new(get_index_path,
                               :create => true,
                               :analyzer => DescriptionAnalyzer.new)

get_index_path is a method to calculate the path to use.

The problem is that my token_stream method is never called.

I'm using ferret 0.9.1 from rubygems, ruby is:

ruby 1.8.4 (2005-12-24) [i486-linux]

I'm running this in a rails app, but the script that creates the index
only uses ActiveRecord to iterate all the records and index them.

Any ideas?

Greetings,

Pedro.
David B. (Guest)
on 2006-04-25 11:24
(Received via mailing list)
Sorry Pedro, you can't create your own analyzer in 0.9.1. If you want
to check out the latest version from subversion, this should work.

Cheers,
Dave
This topic is locked and can not be replied to.