No commit activity in last 3 years
No release in over 3 years
Sunspot support for Mongo Mapper and Mongoid.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Gem Version Build Status

Installation

Mongo Mapper

Put the following in your Gemfile:

gem 'mongo_mapper'
gem 'sunspot_mongo'

Then run:

rails g mongo_mapper:config
rails g sunspot_rails:install
rake sunspot:solr:start

Mongoid

gem 'mongoid'
gem 'sunspot_mongo'

Then run:

rails g mongoid:config
rails g sunspot_rails:install
rake sunspot:solr:start

Upgrading

When upgrading to a new version, don't forget to check UPGRADING for notes about breaking changes.

Usage

Add the following to your model (assuming you have a string field named "content"):

include Sunspot::Mongo
searchable do
  text :content
end

Then search like usual:

search = Article.search do
  fulltext "something interesting"
end
search.results

Note: Mongoid adds Article.search, use Article.solr_search instead.

Reindexing Objects

If you are using Rails, objects are automatically indexed to Solr as a part of the save callbacks.

You can reindex a collection by calling .reindex directly on the model class. When using Mongoid, #reindex can be called on a search scope or criteria, reindexing only the matching objects.

Article.reindex

# Mongoid only
Article.pending.reindex
Article.where(status: "posted").reindex

Note: #reindex on a MongoMapper search will always reindex the entire collection.

If you make a change to the object's "schema" (code in the searchable block), you must reindex all objects so the changes are reflected in Solr. Run:

bundle exec rake sunspot:reindex

More info

See the Sunspot documentation.

Credit

Based on sunspot_mongoid by jugyo. Originally developed by balexand.