A Rails plugin that drops into models and provides indexing functionality. Uses an adapter/repository pattern inspired by Datamapper to abstract the actual indexer used in the background, and exposes the model to a simple indexing API.
This should be used in conjunction with BigRecord in order to provide a more complete ORM.
-
Solr
-
Sphinx (planned)
(1) Install the Solr search server into your Rails application with the bigindex-solr package [github.com/openplaces/bigindex-solr]. Alternatively, if you want to setup your own Solr server, you’ll need to read the [Solr schema] section below and take note of the Solr url to connect to.
(2) In your Rails application, add Bigindex as a gem to your config/environment.rb file:
config.gem "bigindex", :source => "http://gemcutter.org"
and run the following rake task to install all the gems listed for your Rails app:
[sudo] rake gems:install
(3) Add the following line to the bottom of your RAILS_ROOT/Rakefile
require 'big_index/tasks'
(4) Create a Bigindex config file for your Rails application
rake bigindex:generate_config
(5) Modify the config file config/bigindex.yml to correspond to your Solr server.
Modify your Ruby class/model similarly to the following:
class Model < BigRecord::Base include BigIndex::Resource # 1. Include the BigIndex::Resource module into your model. column :name, :string column :description, :text index :name, :string # 2. Define each attribute you want to index along with its type. index :description # Defaults to type :text end
BigIndex will then override the default Model.find() method to pass through the indexer first. Model.find() will also accept the option “:bypass_index => true”, which bypasses the indexed #find method and dispatches it to the original Model.find() method, e.g. Model.find(:all, :bypass_index => true). Alternatively, you can use Model.find_without_index(:all) for the same functionality.
The {BigIndex::Model#index} macro here is used to define which fields will be indexed, and how they will be returned. Please refer to that method for more information.
Once you have your models setup with Bigindex, you will need to rebuild the index. To do so, run the rake task:
rake bigindex:rebuild_index
This rake task accepts the following options:
* BATCH_SIZE: Defaults to 100. For each model, it will batch process this number of records at a time. * CLEAR: Defaults to true. Before rebuilding the model, drop the current index before rebuilding it. * OPTIMIZE: Defaults to true. A Solr option to optimize the index after it's created.
An example usage is:
rake bigindex:rebuild_index BATCH_SIZE=150 CLEAR=true OPTIMIZE=true
To drop the index of your current environment, use:
rake bigindex:drop_index
This will drop the index of any model in your RAILS_ROOT/app/models folder that includes BigIndex::Resource. Be very careful with this task!
Bigindex has a defined schema to use with Solr. If you need to set up Solr yourself, you’ll need to either use the schema.xml defined in this project, or create a merged version of it with your own. You can find the schema file here: github.com/openplaces/bigindex/blob/master/schema.xml
Bigindex is released under the MIT license.
Bigindex was derived from the work of Data Mapper and parts of acts_as_solr.
-
Contact Us
-
Website - www.bigrecord.org
-
IRC Channel -
#bigrecord
on irc.freenode.net
-