1

I am in the process of upgrading my app from Rails2 to Rails3.
My Rails2 app uses searchlogic heavily.
After googling i've come to know that searchlogic is not compatible with Rails3 and need to use meta_search instead.

But i havent quite understood the usage of meta_search vis-a-vis searchlogic.

If i have a User model with :name and :address fields, i am not able to use the following methods with meta_search. What am i doing wrong?

ruby-1.9.2-p0 > User.name_null  
NoMethodError: undefined method `name_null' for #<Class:0x000000038d5ce0>
from /home/pratik/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in `method_missing'
from (irb):7
from /home/pratik/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'  
from /home/pratik/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /home/pratik/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

None of the methods like User.user_id_eq(1) or User.name_equals("Blah") are working. I guess i havent understood the usage of meta_search yet!

Ref:
meta_search https://github.com/ernie/meta_search

Pratik Khadloya
  • 12,509
  • 11
  • 81
  • 106

2 Answers2

1

The methods are attributes to be set in a FormBuilder. As such, you'll want to call user_name_equals = "Bob", not user_name_equals("Bob"). Also, they'll be on a search instance, not the model itself.

@search = User.search(:user_name_eq => "Bob")

If you're looking for something to use in day to day query construction, try MetaWhere instead. http://metautonomo.us/projects/metawhere

Ernie
  • 896
  • 5
  • 7
  • Thanks Ernie for the response and the nice plugin for search in Rails3. But with meta_where also i don't get the searchlogicy syntax. I guess it will be good to have some kind of wrapper methods over meta_where which exhibit searchlogic syntax to enable a smooth migration from Rails2 to Rails3. – Pratik Khadloya Nov 30 '10 at 19:19
1

Keep an eye on rd_searchlogic, which looks to be compatible with Rails 3, though still a preview as of this writing.

EDIT

As described in this SO thread, install via:

  gem 'rd_searchlogic', :require => 'searchlogic', :git => 'git://github.com/railsdog/searchlogic.git'
Community
  • 1
  • 1
zetetic
  • 47,184
  • 10
  • 111
  • 119
  • I tried rd_searchlogic too, it has the same problem `method_missing'. – Pratik Khadloya Dec 01 '10 at 01:34
  • Rails3 is going through a lot of transformation quickly esp 'arel'. I am somehow not feeling comfortable upgrading at this moment as its breaking searchlogic and vestal_versions. I guess i will wait for some time till a stable core and corresponding plugins are available like the wonderful Rails 2.3.5 release we had. – Pratik Khadloya Dec 01 '10 at 05:28