freelancing-god/thinking-sphinx — pull request #325 by hunterae (2012-01-13 18:07:16+00:00)
Title: Added ability to specify additional local indexes to add to a generated distributed index

When defining an index, you can now specify additional local indices to include in the distributed index. This is particularly useful if you have data in multiple different databases. For example, if I have an "external_persons" table that exists in a "peoples" database, and a "credit_cards" table that exists in a different database:

class ExternalPerson < Base::People
define_index "people_by_name" do
indexes [first_name, last_name]

has :id

use_local_index :credit_card_by_name
end
end

class CreditCard < ActiveRecord::Base
define_index "credit_card_by_name" do
indexes [cardholder_first_name, cardholder_last_name]

has person_id, :as => :id
end
end

When we build the configuration, we will see:

index people_by_name
{
type = distributed
local = people_by_name_core
local = credit_card_by_name_core
}

This enables me to run:

ThinkingSphinx.search "Thrifty Mcgee" :index => "people_by_name"

and my results will include both ExternalPeople objects and CreditCard objects.