Google Groups

Re: facets?

Picky / Florian Hanke Jul 19, 2012 11:28 PM
Posted in group: Picky-Ruby
Hi David,

Until I have actually built and optimised facets into the system, the following solution might work quite well for you:

Let's assume you have :name and :surname.
Let's also assume you have filtered on name "david".

So you take all the unfiltered facets (see the gist I sent earlier, finder is a Picky::Search):

filtered_facets_with_totals = index.facets(:surname).map do |token, size|
   result = "name:david surname:#{token}", 0, 0 # name:david represents all the filters that have already been selected
   [token,] { |_, total| total > 0 }

In words: Take all the unfiltered facets for a certain category. For each unfiltered facet, run a query including the previously selected filter(s) it to determine if the facet needs to be shown. It needs to be shown if it has more than one result.
Note that I wrote this off the top of my head.

This might look very pedestrian, but it won't be slow – Picky breaks off prematurely if there isn't a successful result in sight.
Does that help?


On Friday, 20 July 2012 16:05:15 UTC+10, David Lowenfels wrote:
It is the facets that I want to use to refine the query. For instance, search for skis, then refine by men's or women's, or by brand. How could it be possible to run facets only on a subset of the index?