0

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

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

4

1 回答 1

-1

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

于 2013-06-29T10:21:28.333 回答