I’m using Sunspot 1.3.0 in a Rails project.
Post.search do
with(:category_ids, [1, 3, 5])
end
will match Posts with a category of 1, 3, or 5.
What is the correct syntax to match posts with categories of exactly 1, 3 and 5?
E.g. Posts where
category_ids = [1] – doesn’t match
category_ids = [1, 3] – doesn’t match
category_ids = [1, 3, 5] – does match
category_ids = [1, 3, 5, 7] – doesn’t match
I tried
with(:category_ids).equal_to([1,3,5])
but this gives me the following error:
undefined method `gsub’ for [“1”, “3”, “5”]:Array
So, I ended up using “all_of” to solve this problem.
In case it helps anyone else, this is what I did:
This will match Posts categories of [1,3,5], but also Posts with any additional categories, e.g. [0,1,3,5,7] will match, too.
Once Sunspot had returned its result set, I filtered out the Posts which didn’t match exactly.
This does what I want, but I’d hoped there was a more concise way to do this.