It seems what I was looking for was facets.
My define_index block:
define_index do
indexes title, :sortable => true
has created_at, is_active
has categories(:id), :as => :category_ids, :facet => true
end
Product.facets "chocolate" => {:category_ids=>{6=>2, 1=>30, 7=>8,
8=>11, 3=>95, 4=>4}
Sweet.
On Feb 16, 2:46 pm, Nik Bauman <[email protected]> wrote:
> I have a product model, with a HABTM relationship with Categories.
>
> My define_index is as follows:
>
> define_index do
> indexes title, :sortable => true
> ...
>
> has created_at, is_active
> has categories(:id), :as => :category_ids
> end
>
> I'm trying to do a search that will provide me with a count indicating
> how many matching results there are per category.
>
> My query: Product.search("tea", :group_by =>
> 'category_ids', :group_function => :attr )
>
> My query returns 1 product for every category that has a matching
> result, I believe. Is there any way to figure out the total number of
> matching results for that category?
>
> Thanks,
> Nik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---