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

发布于 2024-10-18 14:27:40 字数 922 浏览 2 评论 0原文

假设以下模型:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花伊自在美 2024-10-25 14:27:40

根据索引方法的文档:

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 

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:

 define_index do
     indexes tickets.technician.name, :as => :technician_name
 end 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文