Q:

Searching across multiple active record models without using using sphinx or solr

What's the best way of searching across multiple active record models without using something like sphinx or solr?

A:

I use IndexTank http://indextank.com/

A:

The simplest solution is to inherit models from the one and to store it in one table. However it's very bad if you have an existent schema or if models differs much.
Another (and i think, much better) solution (if your database allow it) - to use UNION in your SQL to get results from multiple tables. In this case you should use find_by_sql.
For example, if you have Post and Question models and want to list both in one list (and filter them by some conditions, possible) you should:

Add field type to each table with default value matching model name. For example:
create_table :questions do |t|
  t.text :text
  t.string :type, :null => false, :default => 'Question'

  t.timestamps
end

Query both models as following:
Post.find_by_sql("SELECT id,type,created_at,updated_at,title,description,NULL AS text FROM posts 
  UNION SELECT id,type,created_at,updated_at,NULL as title, NULL AS description, text FROM questions 
  ORDER BY created_at DESC")

Using type field Rails will distinguish different models and return list of both Post and Question, so you may search (or paginate) for both.

