Project

bigindex

0.0
No commit activity in last 3 years
No release in over 3 years
A Rails plugin that drops into models and provides indexing functionality.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0.0.7
 Project Readme

BigIndex¶ ↑

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.

Supported search servers¶ ↑

  • Solr

  • Sphinx (planned)

Installation¶ ↑

(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'

NOTE: Skip steps (4) and (5) if you’re using the bigindex-solr package.¶ ↑

(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.

Getting Started¶ ↑

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.

Rebuilding your index¶ ↑

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

Drop current index¶ ↑

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!

Solr schema¶ ↑

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

License¶ ↑

Bigindex is released under the MIT license.

Credit¶ ↑

Bigindex was derived from the work of Data Mapper and parts of acts_as_solr.

  • Contact Us