No commit activity in last 3 years
No release in over 3 years
A Sunspot wrapper for MongoMapper that is like sunspot_rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

sunspot_mongomapper

A Sunspot wrapper for MongoMapper based on the excellent wrapper for Mongoid written by jugyo.

Special thanks to @peterlind for submitting some crucial fixes to Sunspot Mongoid that I was able to adapt for Sunspot MongoMapper.

Install

gem install sunspot_mongomapper

The sunspot gem currently has an issue with loading the config/sunspot.yml, for now you can work around it by creating an initializer. config/initializers/sunspot.rb

require 'sunspot'
require 'mongo_mapper'
require 'sunspot/rails'
require 'yaml'

# Override the sunspot url since the yml doesn't work.
sunspot_config = YAML.load_file("#{Rails.root}/config/sunspot.yml")
Sunspot.config.solr.url = "http://#{sunspot_config[Rails.env]["solr"]["hostname"]}:#{sunspot_config[Rails.env]["solr"]["port"]}/solr"

Then you just need a sunspot.yml to configure your environments like so:

production:
  solr:
    hostname: localhost
    port: 8080
    log_level: WARNING
    # read_timeout: 2
    # open_timeout: 0.5
development:
  solr:
    hostname: localhost
    port: 8983
    log_level: INFO
test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING

Finally you'll want to read up on Solr configuration, particularly with regards to autoCommit in your solrconfig.xml and dynamicFields in your schema.xml.

Examples

class Post
  include MongoMapper::Document
  key :title, String

  include Sunspot::MongoMapper
  searchable do
    text :title
  end
end

For Rails3

as gem:

add a gem to Gemfile as following,

gem 'sunspot_mongomapper'

as plugin:

add gems to Gemfile as following,

gem 'sunspot'
gem 'sunspot_rails'

and install sunspot_mongoid as rails plugin,

rails plugin install git://github.com/sylvainsf/sunspot_mongomapper.git

Links

Copyright

Copyright (c) 2012 sylvainsf. See LICENSE for details.