Ferret on Ruby 1.9.1
Categories rails, ruby | 24 March, 2009 | By Stephen Sykes
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.
RSS
[...] 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 [...]
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?
@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.
Great work Stephen!
Just wanted to let you know that I’ve published aaf 0.4.4 containing Thomas’ fixes for 1.9 today.
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.
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.
Whoops, the file went missing when I upgraded wordpress. It is now restored to the proper place – please try again.
Thanks Stephen for the quick response. Its working great!
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)