【问题标题】:Setup Sunspot-search with a has_many ... through-connection使用 has_many ... 连接设置 Sunspot-search
【发布时间】:2013-06-11 04:51:45
【问题描述】:

我正在尝试实现太阳黑子搜索:我的模型“照片”有_许多“类别”:通过“标签”。因此,搜索应该能够查找照片的名称,并且可以仅搜索那些标记有特定类别的照片 - 参数看起来像这样:
搜索?名称=aaa&categories=bbb+ccc ...例如,应该给出名称中带有 aaa 并且带有 bbb 和/或 ccc 标记的所有照片

问题在于 photo.rb-model 中的可搜索块。我不知道如何设置,has_many 似乎没有帮助:通过可用的连接。

目前我被困住了

photo.rb:

searchable do
  text :name
  ...
  integer :tag_ids, :multiple => true, :references => Tag do |p|
    p.tags.map(&:id)
  end
  integer :category_ids, :multiple => true, :references => Category do
    categories.map(&:id)
  end
  text :categories do |p|
    p.categories.map(&:name)
  end
end

category.rb:
searchable do
  text :name
  integer :id
end

这给了我一个

undefined method `categories' for #<Sunspot::DSL::Search:0x5d7d208>

如何更改可搜索块?非常感谢您!

【问题讨论】:

    标签: ruby-on-rails many-to-many has-many-through sunspot


    【解决方案1】:

    好的,我的控制器语法有误。 has-many-through-relationships 与 sunspot 中的 has-many-relationships 相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多