sunspot_association Gem Version Build Status Dependency Status Coverage Status

Automatic association (re)indexing for your searchable Sunspot models.

Pure magic

class User < ActiveRecord::Base
  belongs_to :company
  searchable do
    associate :text, :company, :name, :phone
  end
end

What it does

The above example will convert to:

searchable do
  text :company_name do; company.name end
  text :company_phone do; company.phone end
end

It will also hook into Company and watch it for changes

Usage

Add to your Gemfile:

gem 'sunspot_association', '~> 0.2.1'

Example

class User < ActiveRecord::Base
  belongs_to :company

  searchable do
    associate :text, :company, :name, :phone
    associate :string, :company, :address, :stored => true

    # Converts to:
    # => text :company_name do; company.name end
    # => text :company_phone do; company.phone end
    # => string :company_address, { :stored => true } do; company.address end
  end
end

class Company < ActiveRecord::Base
  has_many :users

  # This configuration is automatically added by the searchable DSL
  # => sunspot_associate :users, :fields => [:name, :phone, :address]
end

License

sunspot_association is distributed under the MIT License, copyright © 2013 Arjen Oosterkamp