如何钻取关联来为thinking_sphinx创建索引?

时间:2011-02-22 16:03:20

标签: ruby-on-rails ruby-on-rails-3 thinking-sphinx

假设以下型号:

class Order < ActiveRecord::Base  
  belongs_to :customer 
  has_many   :line_items, :dependent => :destroy  
  has_many   :tickets, :through => :line_items, :dependent => :destroy  
end  

class Ticket < ActiveRecord::Base
  has_many :items, :dependent => :destroy
  has_many :services, :through => :items
  has_many :line_items
  has_many :orders, :through => :line_items
  belongs_to :technician  
end  

class Technician < ActiveRecord::Base  
  has_many :tickets
  has_many :items, :through => :tickets
  accepts_nested_attributes_for :tickets, :items
end  

如何在thinking_sphinx

中对此进行索引
Order.tickets.first.technician.name

我明白我能做到

  define_index do
    indexes tickets.technician_name, :as => :technician_name
  end 

如果technician_name是故障单表中的列,但事实并非如此。票证表只有外键。

1 个答案:

答案 0 :(得分:1)

根据索引方法的文档:

http://rdoc.info/github/freelancing-god/thinking-sphinx/master/ThinkingSphinx/Index/Builder#indexes-instance_method

您应该可以浏览以下关联:

 define_index do
     indexes tickets.technician.name, :as => :technician_name
 end