Google Groups

Re: [picky:110] facets?


David Lowenfels Jul 23, 2012 6:44 PM
Posted in group: Picky-Ruby
David L wrote:
> > Product.facet(:gender,"climbing jacket")      => [["women", 5], ["men", 25]]
> these facets total up to 30.
>
> but this says 33:
>
> Product.query("climbing jacket",1000).ids.count
>  => 33

Ah okay I realize the extra three must not have a gender! (at least I hope that's the case because it is an easy explanation)

On Jul 23, 2012, at 5:31 PM, Picky / Florian Hanke wrote:
>  Facets (as I added them in in 4.5.9+) use the indexed weights instead of the ids sizes.
> Also see https://github.com/floere/picky/blob/master/history.textile (4.5.9) for details.

> Product.class_eval("@@products_search").facets(:gender)
 => {"women"=>8.899, "men"=>8.76}

how do I convert this from weights to numbers? Weights don't seem to be very useful to me as an end user…
or do I need to use the code I was using previously to do the sub filter? (see bottom of message)

> Product.class_eval("@@products_search").facets(:gender, filter:"climbing jacket")
 => {}
why am I getting an empty hash for this? I was expecting this would give me the same as my previous code.


> Picky::Search#search has the signature:
> def search text, ids = 20, offset = 0, options = {}
> If you pass in unique: true in the options, it will return unique results. It will be unique top down. That is, id an id has been used for one allocation of categories, eg. [:name, :surname], it will not be used anymore in a following allocation.
okay. I never saw this before because I didn't dig into the code.
shouldn't this method be explained on http://florianhanke.com/picky/documentation.html ?
even in the rdoc there is no mention of options[:unique]


this is the code I refer to above:
> def Product.facet category, query=nil
>     facet = @@products_index.facets(category)
>     return facet unless query
>     facet.map do |token, size|
>       [token, query("#{query} #{category}:#{token.inspect}", 1000).total ]
>     end.select { |_, total| total > 0 }
> end