Hi, I'm trying to add search capability to one of my rails applications. I just need it to search through the mysql columns of quite a few models well. I'm wondering what the best way to do this is. I figure I should use a plugin but I don't see anyone really recommending one over another. Is there one you would recommend over all others? How is acts_as_ferret? Thanks.
I've never used acts_as_ferret
. Here's something you could do. Create a table like so:
create_table(:indexed_models) do |t|
t.column :name, :string
t.column :model_id, :id
t.column :index, :string
end
For each model you want to search on, concatenate the values from the searchable columns to create an "index". Insert the results in to the indexed_models table. Where the name is the model's name, model_id is it's primary key, and index is the searchable content. Use observers to create and update the indexed_models table when the models you've designated as "searchable" change.
Do a text search of the index field of indexed_models, then generate a container of models based on the return model name & primary key.
I've never used this approach either, but I've been meaning too.
Searchlogic might be worth checking out. Mr ryanb just did an awesome railscast on it. If you're looking for a fulltext solution, he also has a screencast on Thinking Sphinx.
I highly recommend Sphinx as a search daemon and indexer. It's really good, customizable and scalable.
As a client and front-end library use UltraSphinx or ThinkingSphinx . The second has a better support recently.