I use "binarylogic-searchlogic" in version 2.3.5 along with Rails 2.3.4.
What I want to do is do a model search for a given value across multiple attributes. I achieve this by clinging all together as
User.first_name_or_last_name_or_email_like(value)
But with a lot of attributes in this search, it tends to be ugly. Instead, I would like to use the searchlogic search engine as follows:
search = User.search search.first_name_like = value search.last_name_like = value .. @users = search.all
So this is a way to search through AND, but I want OR. I found two ways to achieve this, but both of them do not work.
1st: add or_ to the condition
search = User.search search.first_name_like = value search.or_last_name_like = value @users = search.all
This gives me The or_last_name_like is not a valid condition. You may only use conditions that map to a named scope The or_last_name_like is not a valid condition. You may only use conditions that map to a named scope
Second: use search.any
search = User.search search.first_name_like = value search.last_name_like = value @users = search.any
gives me an undefined method any 'for # `.
Any idea? Can I indicate the correct readme point?
Thank you for your welcome help!
edit: time for an ugly workaround:
search = User.search search.first_name_like = value search.last_name_like = value User.find(:all, :conditions => search.scope(:find).gsub('AND','OR'))
It works, but certainly not the way, is it?
ruby-on-rails activerecord searchlogic
xijo
source share