【问题标题】:Is it possible to merge two association tables in Sunspot solr是否可以在 Sunspot solr 中合并两个关联表
【发布时间】: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


    【解决方案1】:

    我认为您应该为每个产品创建一个包含品牌、部门、类别和产品详细信息的文档。
    然后您就可以搜索您想要的内容,并接收您需要的信息。

    【讨论】:

    • 谢谢@Rene。但是如何创建该文档
    • 您可以使用DataImportHandler (DIH) 来导入您的相关数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多