I have built a basic search function in order to search for 3 fields in my database.
The search function is as follows:
def self.search(search)
if search
@search_out = Array.new
@prod_out = find(:all, :conditions => ['name ILIKE ? or supplier_code ILIKE ? or ppd_code ILIKE ?', "%#{search}%", "%#{search}%", "%#{search}%"])
@prod_out.each do |prod|
prod.quantities.each do |quants|
@search_out << quants
end
end
return @search_out
else
nil
end
end
Now its working all great, but I want to add an option that lets say I have name entries in my DB which are “Jack and Jill Movie” and “Jack and Janet Movie”
That if I write in the search field: “Jack Movie”, it will return me both of those entries.
Overall, an ability to search for words in the search field and receive also entries which those words aren’t consecutive in them.
Thanks!
Ok Well I actually found a pretty simple way to do this.
I added this in my function before the “find” itself:
That way I’m adding a ‘%’ between each word which gives a wildcard, so now I can find words which aren’t necessarily consecutive because there is a wildcard between them.