【发布时间】:2015-10-20 10:22:57
【问题描述】:
我的模特是
class Product < ActiveRecord::Base
has_many :category_products
has_many :categories , through: :category_products
has_many :product_tags
has_many :tags, through: :product_tags
我想搜索所有三个模型类别,标签,产品。它工作正常,但我面临的问题是,当我搜索类别和标签时,我想找到相关产品。但是我如何区分仅搜索产品列和何时其关联的表。
我的代码是
@search = Sunspot.search[Product,Category,Tag] do
fulltext params[:search]
paginate(:page => params[:page] || 1, :per_page => 3)
end
@products = @search.results
最后我想得到产品。
【问题讨论】:
标签: ruby-on-rails ruby sunspot-rails sunspot-solr