如何钻取关联来为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
如果technical_name 是门票表中的一列,我可以这样做,但事实并非如此。 Tickets 表只有外键。
Assume the following models:
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
How do you index this in thinking_sphinx
Order.tickets.first.technician.name
I understand that I could do
define_index do
indexes tickets.technician_name, :as => :technician_name
end
if technician_name is a column in tickets table, but it's not. tickets table only has foreign keys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据索引方法的文档:
http://rdoc.info/github/freelancing-god/thinking-sphinx/master/ThinkingSphinx/Index/Builder#indexes-instance_method
您应该能够通过以下关联进行导航:
According to the documentation of the indexes method:
http://rdoc.info/github/freelancing-god/thinking-sphinx/master/ThinkingSphinx/Index/Builder#indexes-instance_method
You should be able to navigate through associations like: