Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Easily integrate Mongo Mapper with with Solr search.

branch: master
README.rdoc

tsxn-mongomapper-search

Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG before updating the gem.

Credits

Earlier versions < 1.0.0 were based off the mongomapper-search gem written by Fernando Meyer that can be found at github.com/fmeyer/mongomapper-search.

Usage

Version 1.0.2

To make a MongoMapper::Document indexable add the following line to include the functionality:

include Search::Indexable

The Solr URL must be specified using the :solr_url method. e.g.

solr_url “localhost/solr/some.core” To specify that the index and delete operations into Solr should be force committed the :idx_force_commit method must be passed a value of true. It currently defaults to a value of false. e.g.

idx_force_commit true

To specify which attributes that need to be indexable pass hashes with the attributes and the corresponding indexed names to the :idx_attr method. e.g.

	idx_attr :_id => "object_id", :name => "title", :foo => "bar"

To specify which :many associations that need to be indexable pass hashes with the name of the associations and the namespace the attributes of the association should be indexed under to the :idx_assoc method. A blank namespace will result in no namespace to be pre-appended to the association attribute names. e.g.

idx_assoc :object_relations => “foo” To add search functionality add the following line to include:

include Search::Searchable

An indexing example

Define a EmbeddedDocument model and specify the indexable fields. The following model does not specify the Solr URL because it is a not a first class document. class Project include MongoMapper::EmbeddedDocument include Search::Indexable idx_attr :name => “proj_name” key :name end Define a Document model and specify the indexable fields and associations.

class Employee include MongoMapper::Document include Search::Indexable include Search::Searchable solr_url “search-api.search.com/solr/employee.core” idx_attr :_id => “emp_id”, :name => “emp_name” idx_assoc :projects => “emp_project” idx_force_commit true key :name many :projects end

Saving an instance of Employee causes that employee to be indexed in Solr. The Lucene document that's indexed would appear something like:

employee doc emp_id = val emp_name = val emp_project.proj_name = val1 emp_project.proj_name = val2 emp_project.proj_name = .… emp_project.proj_name = valN

A searching example

Employee.search('emp_name:“John Doe” emp_project.proj_name:“search”', :qt => 'dismax')

Feedback & Contributions

If the documentation here is not very clear please email me any suggested improvements. Also if you would like me to pull changes from a fork to the master let me know.

Something went wrong with that request. Please try again.