No commit activity in last 3 years
No release in over 3 years
Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.7.0
>= 0.12.1
>= 2.3.11
 Project Readme

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.