Ferret on Ruby 1.9.1

I took the trouble to port ferret to ruby 1.9.1 yesterday evening.  I have it working on my mac. Here’s a gem for you to try – I have labelled it  If you use it let me know how it runs, but it’s at your own risk, I haven’t extensively tested it. [UPDATE: this gem has been updated 5th April 2009 – please test.  There is also a fork at github] I’ve made mostly simple changes in the code:

  • Changed all struct RString -> ptr to use the RSTRING_PTR macro, except for cases where it was being used to add items to an array where rb_ary_store was used.
  • Changed all struct RString -> len to use the RSTRING_LEN macro
  • Changed all struct RArray -> ptr to use the RARRAY_PTR macro
  • Changed all struct RArray -> len to use the RARRAY_LEN macro
  • Removed manual adjustment of the len member of RArray. In fact ruby 1.9 stores small arrays of 3 items or less differently from larger ones, and this adds complexity. It is better to use the rb_ary_store method which will use the correct pointer and will keep the length in sync with the number of items in the array.
  • Changed all struct RHash -> tbl to ntbl
  • Removed references to rb_thread_critical
  • Removed 4th argument from calls to rb_cvar_set
  • Included ruby/re.h and not regex.h, and altered tokenizer code to correctly use the new regexp library
  • Included ruby/st.h and not st.h
  • Some other minor changes to error messages formats causing compiler warnings

By the way, acts_as_ferret also runs with some very minor surgery, Thomas von Deyen has a fork here.


23 thoughts on “Ferret on Ruby 1.9.1

  1. Hi Stephen. Great work.Do you sent a pull request to David Balmain? I think this is some important fix.Do you have a an fork of the acts_as_ferret gem, i can’t find it on github. Acts_as_ferret fails for me with your ferret gem, any idea?

  2. @tvdeyen: Yes, I sent a pull request some time ago, but no response as yet.AAF – I went to make a fork but noticed you have already done it yourself – I have updated this post with a link.

  3. Great work Stephen!Just wanted to let you know that I’ve published aaf 0.4.4 containing Thomas’ fixes for 1.9 today.

  4. Hi Stephen,Thank you very much for the ferret gem for 1.9, it’s working great! I appreciate the work you did for the fixes.

  5. Hi Stephen,Is the gem file still available for download? I could not download it. I am stuck with my project as we have to move on to Ruby 1.9.1 and we are using ferret. The acts_as_ferret v0.4.4 installed successfully. But not ferret with Ruby 1.9.1. Any help will be appreciable. Thank you.

  6. Whoops, the file went missing when I upgraded wordpress. It is now restored to the proper place – please try again.

  7. ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]Ferret code freshly cloned from http://github.com/sdsykes/ferret .When I try to rake test in the ruby/ dir, the build fails with this:(snip)/home/pistos/usr/bin/ruby19 -I"lib:test/unit" "/home/pistos/usr/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/tc_document.rb" "test/unit/tc_field_symbol.rb" "test/unit/ts_analysis.rb" "test/unit/ts_index.rb" "test/unit/ts_largefile.rb" "test/unit/ts_query_parser.rb" "test/unit/ts_search.rb" "test/unit/ts_store.rb" "test/unit/ts_utils.rb"/misc/git/ferret/ruby/lib/ferret.rb:25:in `require’: Unknown SortField Type (ArgumentError) from /misc/git/ferret/ruby/lib/ferret.rb:25:in `’ from /misc/git/ferret/ruby/test/test_helper.rb:21:in `require’ from /misc/git/ferret/ruby/test/test_helper.rb:21:in `’ from /misc/git/ferret/ruby/test/unit/tc_document.rb:1:in `require’ from /misc/git/ferret/ruby/test/unit/tc_document.rb:1:in `'(snip)

  8. Hi there,well, the ferret gem does something, most error messages disappear, but one error message still remains after starting the server:/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/vendor/builder-2.1.2/blankslate.rb:41:in `reveal’: Dont know how to reveal method methods (RuntimeError)So unfortunately I am still stuck with Suse Linux 11.2 and Ruby 1.9.1 and Rails 2,3,5. what do you recommend? Installing another Ruby version?

  9. Would you mind pushing your gem to rubygems.org as sdsykes-ferret or something? I would love to have my Gemfile conditionally require your gem when under 1.9+, otherwise falling back to using the "official" gem.

  10. dbalmain has Stephen’s commits in his branch, so maybe we should just ask him to generate a new version of official Ferret gem for all of us to use?

  11. Hi I am trying to run ferret on windows XP using Ruby1.91 I have compiled and installed the sdsykes-ferret gem, and it seems to run ok using the RAM disk option. But when I try to specify an index_dir / path, I get the following error:——————————-C:/Ruby191/lib/ruby/gems/1.9.1/gems/ferret-0.11.6/lib/ferret/index.rb:138:in `initialize’: IO Error occured at :117 in xpop_context (IOError)Error occured in index.c:901 – sis_find_segments_file
    Error reading the segment infos. Store listing was
    from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ferret-0.11.6/lib/ferret/index.rb:138:in `new’
    from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ferret-0.11.6/lib/ferret/index.rb:138:in `initialize’
    from C:/sandbox/ml/test_ferret.rb:8:in `new’
    from C:/sandbox/ml/test_ferret.rb:8:in `’——————————-

  12. excuse me, I mean:C:/Ruby191/lib/ruby/gems/1.9.1/gems/sdsykes-ferret- `initialize’: IO Error occured at :117 in xpop_context (IOError)Error occured in index.c:901 – sis_find_segments_file
    Error reading the segment infos. Store listing was
    from C:/Ruby191/lib/ruby/gems/1.9.1/gems/sdsykes-ferret- `new’
    from C:/Ruby191/lib/ruby/gems/1.9.1/gems/sdsykes-ferret- `initialize’
    from C:/sandbox/ml/test_ferret.rb:8:in `new’
    from C:/sandbox/ml/test_ferret.rb:8:in `’

  13. This looks like the kind of error you get with a corrupted index.Can you tell me exactly what you are doing to get the error?

  14. Sorry I never got a chance to reply…just been to busy to get to the winws versionAll I was doing was trying to index and search for a document…the simplest thing possible.I did try to install sdsykes on a 64bit Centos machine with ruby 1.8.7…did not takeOn a side note, I recently patched a memory leak in the lattest release of ferret 11.6 :http://stackoverflow.com/questions/2003885/garbage-collection-with-ruby-c-extensionThis fix really belongs in any new releases

  15. Here are the errors I get on 64 bit linux with ruby 1.8.7…gcc -I. -I/home/charles.martin/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/x86_64-linux -I/home/charles.martin/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/x86_64-linux -I. -fPIC -g -O2 -fPIC -D_FILE_OFFSET_BITS=64 -c r_search.cr_search.c: In function ???frt_mtq_set_dmt???:r_search.c:625: error: too few arguments to function ???rb_cvar_set???r_search.c: In function ???frt_fq_set_dms???:r_search.c:1428: error: too few arguments to function ???rb_cvar_set???r_search.c: In function ???frt_fq_set_dpl???:r_search.c:1460: error: too few arguments to function ???rb_cvar_set???r_search.c: In function ???Init_MultiTermQuery???:r_search.c:3108: error: too few arguments to function ???rb_cvar_set???r_search.c: In function ???Init_FuzzyQuery???:r_search.c:3417: error: too few arguments to function ???rb_cvar_set???r_search.c:3419: error: too few arguments to function ???rb_cvar_set???make: *** [r_search.o] Error 1

  16. It would be helpful if you could include this bug fix in your distributionhttp://stackoverflow.com/questions/2003885/garbage-collection-with-ruby-c-extension/3774808#3774808

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s