I'm trying to implement a Sunspot-search: My model "Photo" has_many "Categories" :through "Tags". So the search should be able to look for a photo's name and with the possibility to search for only those, that are tagged with a certain category- with the params looking like such:
search?name=aaa&categories=bbb+ccc
...which, as an example, should give all photos with aaa in the name and that are tagged with bbb and/or ccc
The problem lies in the searchable block in the photo.rb-model. I can't figure out, how to set things up and there seems to be no help for has_many :through connections available.
Currently I'm stuck with
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
which gives me a
undefined method `categories' for #<Sunspot::DSL::Search:0x5d7d208>
How do the searchable blocks have to be altered? Thank you very much in advance!
ok, there was a mistake in my controller-syntax. has-many-through-relationships are just the same as has-many-relationships in sunspot.