Need some suggestions on search strategy

I need some suggestions for the best way to implement search for my
client. They have several models (project, request, usage, etc.) that
they need to search for. Each model will have its own search page
with a form that is similar to the one shown for editing. So the
search needs to be across model fields and the results are limited to
the model.

Some of the model fields will be for associations (like comments) but
again we're only interested in returning a single model. For some of
the models we also want to filter results based on a parent. For
example, when searching requests we want to limit the requests to a
specific project.

Finally, for one of the models, we need full text searching across
fields (as opposed to a search form with inputs for every field.) The
search is still limited to returning only results for a specific
model. There would also be one or two filters so the user could
explicitly limit a few select fields.

I would really appreciate any suggestions you might have on the
general approach you would use to solve this problem. I'm using Rails
2.1 btw so named scope is available.



I've implemented something like this with ferret & acts_as_ferret

this line:

acts_as_ferret :fields => {:name => {:boost => 3}, :description =>
{:boost => 2, :store => :no}, :tag_list => {}},
                 :index_dir => File.join(RAILS_ROOT, "public",

is all I need to allow easy searching
In this case it's mixed with acts_as_taggable and indexes name,
description and the tags

put the search text in @query and make something like this:

@products = Product.find_with_ferret(@query,
                                          {:page =>
params[:page].to_i, :per_page => params[:per_page].to_i},
                                          {:conditions =>
["(products.status = 1 AND products.created_at BETWEEN ? AND ?)",
"#{query_start_date} 00:00:00", "#{query_end_date} 23:59:59"],
                                           :order => @sort})

allowing for a mix of fulltext & database search
As you may see, pagination is included

Another option that quite some people seem to like is ultrasphinx
I haven't used it yet, but people seem to be happy with it

I knew about ferret but I had forgotten that you can filter ferret
with conditions (and filtering is key for me.) Turns out you can
filter with something like

@posts= Post.find_with_ferret(query, {:page =>
params[:page], :per_page => per_page}, :conditions => ['category_id
= ?', category_id])

Thanks for the tip.



We've implemented similar searches using acts_as_ferret and it's been
easy to use, pretty fast and efficient. I'm not 100% about how
scalable it is but I suspect it'll do very well.
I'd highly recommend it - you should be able to get it up and running
in less than a day.