Sunspot makes it easy to do full text searching through Solr. Here I show how to search on various attributes and add facets for filtering the search further.
bundle
rails g sunspot_rails:install
rake sunspot:solr:start
rake sunspot:reindex
Gemfile
gem 'sunspot_rails'
models/article.rb
searchable do
text :name, :boost => 5
text :content, :publish_month
text :commentsdo
comments.map(&:content)
end
time :published_at
string :publish_monthenddefpublish_month
published_at.strftime("%B %Y")
end
articles_controller.rb
defindex@search = Article.search do
fulltext params[:search]
with(:published_at).less_than(Time.zone.now)
facet(:publish_month)
with(:publish_month, params[:month]) if params[:month].present?
end@articles = @search.results
end