views:

36

answers:

0

Note: I'm having a hard time explaining this, so please ask questions and I'll try to refine the problem as much as possible.

Assuming I have the following category structure:

- Planets
  - Earth
  - Mars

And the following items/categories (nevermind that some of them don't logically make sense):

- Item #1
  - Category: Planet
  - Category: Earth

- Item #2
  - Category: Planet

- Item #3
  - Category: Earth

If I set up a search on 'Item', the category counts I get returned would be:

- Planet (2)
- Earth (2)

However, since Earth is a child of Planet, I would want to display something more akin to

- Planet (3)
  - Earth (2)

Where clicking on Planet would return all 3 results (the 2 results with 'Planet' explicitly specified and the 1 result whose category is a child of 'Planet').

Is there an efficient pattern for doing this?

If it helps, I'm using rails with the awesome_nested_set gem to manage my hierarchies and thinking_sphinx to do the searching (where categories are specified as facets).