【发布时间】:2012-08-17 07:28:47
【问题描述】:
我有四张桌子。它们是品牌、部门、类别和产品详细信息。模型是
品牌型号
class Brand < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
部门模型
class Department < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
类别模型
class Category < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
产品详细型号
class ProductDetail < ActiveRecord::Base
belongs_to :department
belongs_to :category
belongs_to :brand
searchable do
text :name
text :brand do
brand.name
end
integer :department_id
integer :category_id
end
如果用户首先搜索部门 1,我将根据部门 ID 获取所有产品详细信息。结果表还必须包含品牌名称、类别名称和部门名称。是否可以使用 sunspot solr 来做到这一点?怎么样?
【问题讨论】:
标签: ruby-on-rails-3 sunspot sunspot-rails sunspot-solr