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

20 comments for this post.

  1. Pingback from Strange bug in irb1.9 | keyongtech | 24 March 2009 | 10:07 pm :

    [...] 0); —8<— two side notes: 1) in ruby-1.9.1 some macros changed (see http://pennysmalls.com/2009/03/24/ferret-on-ruby-191/ for example): —8<— int i; – for(i =3D 0; i < RARRAY(children)->len; i++) { – VALUE key [...]

  2. Comment from tvdeyen | 3 May 2009 | 4:35 pm :

    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?

  3. Comment from Stephen Sykes | 4 May 2009 | 10:58 am :

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

  4. Comment from Jens Krämer | 29 May 2009 | 12:01 am :

    Great work Stephen!

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

  5. Comment from Lee Hinman | 22 June 2009 | 9:40 pm :

    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.

  6. Comment from Ashif Manjur | 29 August 2009 | 10:38 am :

    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.

  7. Comment from Stephen Sykes | 29 August 2009 | 11:20 am :

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

  8. Comment from Ashif Manjur | 29 August 2009 | 4:45 pm :

    Thanks Stephen for the quick response. Its working great!

  9. Comment from Pistos | 25 November 2009 | 4:12 am :

    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)

  10. Comment from Techo2RailsTeam | 26 March 2010 | 12:33 pm :

    firstly thanks thanks thanks
    i downloaded u r ferret and installed it worked well
    thanks again
    guru

  11. Comment from Manfred | 15 April 2010 | 8:01 pm :

    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?

  12. Comment from Stephen Sykes | 15 April 2010 | 8:58 pm :

    This is a rails problem, but looks like it will be fixed when 2.3.6 comes out.

    https://rails.lighthouseapp.com/projects/8994/tickets/3001-blankslate-is-not-ruby-19-compatible

    AAF uses BlankSlate, but it could avoid this. There is a ticket there too:
    http://j-k.lighthouseapp.com/projects/45560/tickets/3-rails-232-ruby-191-acts_as_ferret-raises-exception

    One possibility for a quick fix would be to redefine BlankSlate in a plugin, using the patches in the rails ticket.

  13. Comment from Dan Kubb | 3 June 2010 | 9:06 am :

    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.

  14. Comment from Stephen Sykes | 6 June 2010 | 8:31 pm :

    Hi Dan,

    It’s there, and sdsykes-ferret it is.

    -Stephen

  15. Comment from Tomash | 8 June 2010 | 9:07 am :

    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?

  16. Comment from charles | 21 August 2010 | 12:20 am :

    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 `’

    ——————————-

  17. Comment from charles | 21 August 2010 | 12:44 am :

    excuse me, I mean:

    C:/Ruby191/lib/ruby/gems/1.9.1/gems/sdsykes-ferret-0.11.6.19/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/sdsykes-ferret-0.11.6.19/lib/ferret/index.rb:138:in `new’
    from C:/Ruby191/lib/ruby/gems/1.9.1/gems/sdsykes-ferret-0.11.6.19/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 `’

  18. Comment from Stephen Sykes | 22 August 2010 | 4:14 pm :

    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?

  19. Comment from Charles | 2 September 2010 | 5:35 pm :

    I was trying the simplest example . I gave up and moved to a Mac Pro…seems to work fine here

  20. Comment from Charles | 2 September 2010 | 8:56 pm :

    I’ll give some more details this weekend once I get back home.

Leave your comment...

Powered by WP Hashcash

Blog Archives

Navigation


About this blog

A blog about Ruby, Rails and other tech. Mostly.


Find Something?