I successfully installed and set it up searchlogic for basic (keyword) searching. I have the following problem:
@search = Proposal.search(params[:search])
@proposals = @search.all
The above code works properly if I type in a keyword such as “red”. It will bring up everything with red keyword. Or if I type in “green”, it will bring up everything with green as a keyword. However, when I type “red green” in the search box it will ONLY bring up cases where the keywords are BOTH red and green (and not bring up instances where they may only have one of the two keywords). Yes, I am using keywords_like_any. I can see what the general problem is via debug, keywords_like_any: green red. The below code works as I want it to (bring up any instances of red OR green).
@search2 = Proposal.keywords_like_any("red", "green")
@test = @search2.all
I believe what I need to do to solve the issue is turn the first code to view params[:search] as an array? I tried doing params[:string].to_s.split (as shown in railscast) however it did not work.
The
*_like_anyis intended to be used with checkboxes form helpers (f.check_box) which outputs arrays into yourparamshash as opposed tof.text_fieldwhich outputs strings. If you still want to use them with af.text_fieldyou can :Considering that your field is named keyboard here is some code that should solve your problem :
You can skip the line
@proposals = @search.allbecause search results works like an array.