agile-ajax

Installing Edge Ferret/acts_as_ferret

If you do a gem install ferret, you will be getting 0.11.6. The latest stable version of acts_as_ferret is 0.4.3. Both of these versions were released nearly a year ago in November 2007. Since then, there have been various performance improvements and bug fixes which you'll be missing out on. In order to get the latest versions, you'll need to do a little bit of work but I would recommend it if an update is feasible for you.

Since it will be the easiest, let's begin with acts_as_ferret.

acts_as_ferret

Installing the latest version of acts_as_ferret is pretty straight forward, as the documentation for it is pretty clear.

If you are starting a new project:

script/plugin install git://github.com/jkraemer/acts_as_ferret.git

If you are updating an existing project:

script/plugin install git://github.com/jkraemer/acts_as_ferret.git --force

The --force option will force a re-install.

Ferret

Ferret is a bit more involved. The gem on RubyForge is version 0.11.6. Ferret has been moved to github, but sadly the github gem source does not include ferret. In order to install an updated ferret gem, we will need to compile it and install it by hand. Thankfully, this process is not difficult.

Unfortunately, the ferret project site has been down for a few days now. Google cache does have a copy of the instructions from the site for installing edge as a gem on your machine; however, the instructions are old and a little inaccurate for the latest version. Despair not! I went through this process yesterday and this is what worked for me.

Checkout and Compile

First, we need to checkout the latest ferret code. This will require git.

$ cd /tmp
$ git clone git://github.com/dbalmain/ferret.git

Next, let's run the tests to make sure everything is working right. This step will compile the code, which will take a little bit of time before the tests are run.

$ cd ferret/ruby
$ rake

If this fails, you will need to make a slight change to the rake task. I got the following error message while running this on a mac: rake aborted! WIN32 has been removed, use CURRENT instead.

Do the following step only if you get this error and you are not on a windows machine.
Change the following lines in ferret/ruby/Rakefile

windows = (RUBY_PLATFORM =~ /win/) rescue nil
SUDO = windows ? "" : "sudo "

to

windows = false

Then, run rake again.

Now, we need to build the ferret gem.

$ rake package

Simple, right?

Installation

Installing the gem is simple as well.

$ cd pkg/
$ sudo gem install ferret-0.11.8.gem

Of course, if there is a different version number you should use that instead. Feel free to uninstall the old gem if you want.

If you unpacked the ferret gem in your rails app, you will need to remove it and unpack this new version. Navigate to your rails app directory.

$ rm -rf vendor/gems/ferret-0.11.6
$ rake gems:unpack ferret

You will probably need to rebuild your index, as I do not believe a 0.11.6 index is compatible with 0.11.8 (I needed to rebuild it).

$ rake ferret:rebuild

Note that this will only work if you have an existing index built. If not, you will need to create your index. I recommend using a custom rake task, similar to the following:

desc 'create fresh ferret index'
task :ferret_build => :environment do
  [Foo, Bar].each(&:rebuild_index)
end

Invoke that rake task to create your index.

I would highly recommend that you run your tests for your app, to make sure nothing was broken. Assuming everything went well, you should now be using the latest versions of ferret and acts_as_ferret.

Comments: 5 so far

  1. is this stable

    Comment by kishore, Monday, November 24, 2008 @ 5:46 am

  2. I’m having some problems with this. Running the tests via “rake” seemed to compile everything, and ran the tests with 0 failures, 0 errors. Packaging also seemed to work fine, as did installation. I can see the new version of ferret in the output of “gem list”, and I was able to unpack it into vendor/gems.

    But when I run “rake ferret:rebuild” to rebuild my indexes, I get errors:

    $ rake ferret:rebuild --trace
    (in /Users/maalder/Code/Rails/thunderbook.maalder.dev)
    ** Invoke ferret:rebuild (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute ferret:rebuild
    rake aborted!
    You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.split
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/tasks/ferret.rake:9
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/bin/rake:31
    /usr/bin/rake:19:in `load'
    /usr/bin/rake:19

    I am completely baffled and obviously, without an index, I’m getting no search results at all. Any ideas?

    Comment by Alderete, Thursday, December 4, 2008 @ 5:19 am

  3. Hmmm, looking at the ferret:rebuild rake task, it appears you need to provide the name of the index(es) to rebuild in an INDEXES environment variable, ala:

    INDEXES="person project publication skill" rake ferret:rebuild --trace

    But this also errors out, just in a slightly different place:

    $ INDEXES="development" rake ferret:rebuild --trace
    (in /Users/maalder/Code/Rails/thunderbook.maalder.dev)
    ** Invoke ferret:rebuild (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute ferret:rebuild
    rake aborted!
    development
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:264:in `get_index'
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:385:in `rebuild_index'
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/tasks/ferret.rake:12
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/tasks/ferret.rake:10:in `each'
    /Users/maalder/Code/Rails/thunderbook.maalder.dev/vendor/plugins/acts_as_ferret/tasks/ferret.rake:10
    /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
    [...]

    Also, my former method of rebuilding my indexes, simply deleting them and restarting my application, and then running a search, is creating an “index” that looks nothing like the old version, with only two files per model, one of which is empty, and one of which is only a few lines long.

    Maybe getting the latest ferret and acts_as_ferret from the trunk isn’t such a good idea, the currently checked in version is busted…?

    Comment by Alderete, Thursday, December 4, 2008 @ 5:37 am

  4. OK, it looks like the problem is that the SVN repository is no longer being maintained for acts_as_ferret; the repository is now hosted at RubyForge, with a mirror on GitHub. The correct command to install the acts_as_ferret plug-in from the repository is thus:

    script/plugin install git://github.com/jkraemer/acts_as_ferret.git

    Once I did that and rebuilt my indexes, my searches now work. Note that I rebuilt my indexes manually, in script/console, using Model.rebuild_index, e.g., “Person.rebuild_index”. Now that it’s working, I’m too afraid to try the Rake task to do the rebuilding…

    Comment by Alderete, Thursday, December 4, 2008 @ 6:10 am

  5. Yes, you need to have an existing ferret index in order to use that rake task.
    You can either create a custom rake task, or, as you did, hop into the console and manually invoke Foo.rebuild_index.

    I would vote the custom rake task route, as a new person/new environment will need to do that as well.

    Here is a snipet (replace Foo and Bar with your classes):
    desc ‘create fresh ferret index’
    task :ferret_build => :environment do
    [Foo, Bar].each(&:rebuild_index)
    end

    Also, thanks for the github tip. I’ll update my post to use that as the URL.

    Comment by Anthony Caliendo, Tuesday, December 16, 2008 @ 4:36 pm

Leave a comment

Powered by WP Hashcash

Who is Pathfinder?

Topics

Search

WordPress

Comments about this site: info@pathf.com