Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Search multiple fields with single text field using metasearch and rails 3?

I've started using the metasearch gem http://metautonomo.us/projects/metasearch/ for a ruby on rails 3 app after seeing it recommended in another stackoverflow post. I would like to have a single text field on a search form that can search in multiple fields rather than have one text field for each. I just havn't been able to figure it out.

My example below is probably a little more complicated because it also uses Multi-level associations:

Model: Report belongs to site

Model: Site has many reports

View (the index for reports with a search form):

Have something like:

<%= f.text_field :site_name_or_site_address_contains %>

rather than 2 seperate text fields like:

<%= f.text_field :site_name_contains %> <%= f.text_field :site_address_contains %>

The notes on the website and rdocs cover adding new where statements in the initializer. I'm not sure if thats required but I don't really understand them either.

like image 446
Daniel Avatar asked Oct 05 '10 01:10

Daniel


2 Answers

Check out the latest version on GitHub: http://github.com/ernie/meta_search

I've held off on adding that support for a while because I think the syntax gets a bit goofy looking. You might want to check out the support for custom search methods, as well.

like image 103
Ernie Avatar answered Sep 28 '22 20:09

Ernie


For those reading this, the functionality is in meta_search now - it works well.

like image 26
curiouscat Avatar answered Sep 28 '22 20:09

curiouscat