A Sunspot wrapper for Mongoid that just works.
gem 'sunspot_mongoid2'
bundle install
Create config/initializers/sunspot_mongoid.rb
:
Sunspot.session = Sunspot::Rails.build_session
ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
Don't forget to restart your rack server (or pow.cx)
add gems to Gemfile as following,
gem 'sunspot_mongoid2'
gem 'sunspot_rails'
and install sunspot_mongoid
as rails plugin,
rails plugin install https://github.com/hlegius/sunspot_mongoid2.git
class Post
include Mongoid::Document
include Sunspot::Mongoid2
searchable do
text :title
end
field :title
end
class SomeController < ActionController::Base
def index
search = Sunspot.search(Post) do
fulltext params[:q]
end
@results = search.results
@total_lines = search.total
end
end
# http://yourapplication.dev/search?q=foobarbaz
Copyright (c) 2010 jugyo. See LICENSE for details.
A lot of other contributions were made before I did.