【问题标题】:Ruby on Rails Sunspot solr condition on included associationRuby on Rails Sunspot solr 包含关联的条件
【发布时间】:2012-11-30 07:40:47
【问题描述】:

我正在尝试使用 solr 搜索产品,它运行良好。除了我想限制供应商,通过 has_and_belongs_to_many 与 Products 关联,使用供应商模型中的状态字段为 0 或 1。

我的模型是:

“产品.rb”

has_and_belongs_to_many :suppliers, :class_name => 'Company'

searchable do
    text :name
    text :brand
    text :description
end

“公司.rb”

attr_accessible :status

has_and_belongs_to_many :products

对于我正在使用的搜索:

@search = Product.search(:include => :suppliers) do
  fulltext params[:s]
  with :status, 1   # This gives error as status is not a field in Product
end

如何仅包含状态为 1 的供应商?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 solr sunspot sunspot-solr


    【解决方案1】:

    您缺少可搜索的状态

    searchable do
        text :name
        text :brand
        text :description
        boolean :status
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多