Making sense of all the search options


#1

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