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)
firstly thanks thanks thanks
i downloaded u r ferret and installed it worked well
thanks again
guru
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?
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.
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.
Hi Dan,
It’s there, and sdsykes-ferret it is.
-Stephen
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?
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 `’
——————————-
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 `’
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?
I was trying the simplest example . I gave up and moved to a Mac Pro…seems to work fine here
I’ll give some more details this weekend once I get back home.