Reputation: 249
I'm trying to do a search with TS in which the results are grouped by an attribute (in the example: category).
A structure like this (doesn't have to be arrays):
[[id: 1, name: this, category: foo] [id: 2, name: this, category: foo]],
[[id:3, name: this, category: bar], [id:4, name: this, category: bar]]
I think I could get the results sorted by the attribute and then go over the results generating the structure I want by the attribute but what I'm trying to see if it's possible is that TS does this for me without having to use rails to go over every result item.
I need this structure to display the result elements categorised by the attribute.
I've tried using GROUP_BY but it returns only 1 element per attribute which makes me think I either don't understand the GROUP_BY or I'm not doing the query right:
Video.search(Search.build_options.merge({:conditions => {:name => "this"}, group_by: :category}))
I'm using the current versions of Sphinx and Thinking Sphinx,
Upvotes: 0
Views: 79
Reputation: 16226
As Barry's noted in his comments, Sphinx's approach to grouping is to return one record for each grouped attribute value, rather than a collection of results for that value. Thus, Thinking Sphinx behaves this way as well.
If you want collections of results for each value, you're going to have to construct that yourself - you definitely can't rely on TS to do it for you.
Upvotes: 1