Complex search

I have a database table with quite a few fields in it (more than I like,
but needed to meet the specs). I’m needing to do a fairly complex query
that will be built on the fly according to parameters given by the user.
find_by_name_and … isn’t too useful as I’m not sure which fields I’m
finding by until the user enters their data. Also, I’d really be
surprised if rails built in find_by could handle 20 - 25 predicates -
which is possible.

I was looking for a find method that would allow me to simply specify a
condition string ("itemgroup > 2 and buildwidth < 200 and "), but I
don’t see one. I see the find_by_sql, and can certainly use it, but with
the linked tables (owned by) the fields and joins are going to be fun to
build - doable, but fun.

I can’t be the first to run across this need in rails. Is there another
way than find_by_sql - or should I start coding the raw select? Since
I’ve been working in rails, I’ve become kinda lazy.

Thanks in advance
—Michael

Couple of alternatives for you… Put it in an index ala Lucene or its
Ruby sibling Ferret. Or… if you want to keep it pure SQL then…
EZWhere.

http://ferret.davebalmain.com/trac/

http://rubyforge.org/projects/ez-where/