Forum: Ruby on Rails Making sense of all the search options

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sean H. (Guest)
on 2006-01-30 17:48
(Received via mailing list)
Hi everyone,

I have an app that manages accounts.  There's a search function that I
don't like, but it works:

    @person_pages, @people = paginate :person, :per_page => 20,
      :conditions => [ "LOWER(username) LIKE ? OR LOWER(first_name)
LIKE ? OR LOWER(last_name) LIKE ? OR LOWER(preferred_name) LIKE ?",
                     "%" + session[:q] + "%",
                     "%" + session[:q] + "%",
                     "%" + session[:q] + "%",
                     "%" + session[:q] + "%" ], :order => 'username ASC'

What I need is one search function that does this by default, but also
allows me to search each value independently.

I'd love to use a find_by_first_name() finder, but these are all
"like" searches, which isn't supported in that fashion.  This all ends
up looking pretty ugly in the code.

So, on to some gems and other add-ons.

 * Ferret looks awesome, but overkill for this purpose.
 * SearchGenerator might do it, but all I need is a finder to feed a
collection, not views and layouts.
 * ActiveSearch looks like the thing, but I've heard little about it,
so I'm not sure it's still valid.

I'll play with all of these to get a feel, but if anyone has any
thoughts on the best way to search through a table full of name and
title data, I'd love to hear them.

Thanks!

Sean
This topic is locked and can not be replied to.