views:

607

answers:

2

I have a form to a search engine. I want to search for the searchterm in all fields of a specific model.

I'm using the searchlogic plugin. It gives me a lot of new finders but i cannot do a OR between two fields.

for example:

How can i do a "SELECT * from my_table WHERE field1 LIKE '%xpto%' OR field2 LIKE '%xpto%' ?

Specially in the form parameter that will be passed to my controller, if you know searchlogic you know what i'm speaking about, i'm trying to pass something like: field1_or_field2_like("xpto") but it dont works. Any idea?

+1  A: 

Uhm... I don't think Searchlogic offers such functionality by default. But why not write the named_scope yourself?

class MyModel
  named_scope :field1_or_field2_like lambda { |*args| {:conditions => ["field1 LIKE '%?%' OR field2 LIKE '%?%'", args.first, args.first]} }
end
Jongsma
yes, i used this as the in the railcast 111 about named_scope :-)But i would like to know with searchlogic, since i didnt see nothing about OR in any example that they use it :-)
VP
+1  A: 

Based on this post from the plugin's author there is not intended to be support for this, although as Jongsma indicated you can implement it with your own named_scope.

naven87