Sunspot is one of the most used stones for adding search to a Rails application.
Indexing is as follows:
class Post < ActiveRecord::Base searchable do text :title, :body text :comments do comments.map { |comment| comment.body } end integer :blog_id integer :author_id integer :category_ids, :multiple => true time :published_at string :sort_title do title.downcase.gsub(/^(an?|the)\b/, '') end end end
And the search:
Post.search do fulltext 'best pizza' with :blog_id, 1 with(:published_at).less_than Time.now order_by :published_at, :desc paginate :page => 2, :per_page => 15 facet :category_ids, :author_id end
source share