Google Groups

Re: [picky:99] facets?

Picky / Florian Hanke Jul 23, 2012 5:31 PM
Posted in group: Picky-Ruby
Hi David,

On Tuesday, 24 July 2012 09:26:50 UTC+10, David Lowenfels wrote:
Now I'm getting weird results with the latest version (4.5.10)

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

where are the decimals coming from??

Very sorry about not telling you about this change. Facets (as I added them in in 4.5.9+) use the indexed weights instead of the ids sizes.
def Product.facet category, query=nil
    facet = @@products_index.facets(category)
    return facet unless query do |token, size|
      [token, query("#{query} #{category}:#{token.inspect}", 1000).total ] { |_, total| total > 0 }
> Product.facet(:gender,"climbing jacket")      => [["women", 5], ["men", 25]]

these facets total up to 30.

Ok, got it. Please note that in the latest Picky version you can use the facet method on Picky::Search: :gender, filter: 'climbing jacket'
(The query is much faster now with the new version, even before I reindexed.)

Yes, I implemented the first optimisation as described in:
but this says 33:

Product.query("climbing jacket",1000).ids.count
 => 33

Yes. The difference between queries:
1. 'climbing jacket gender:unisex'
2. 'climbing jacket'
is that Picky searches the last token as if it was searched for partially (it's what's expected in 90% of the cases). So it actually searches:
1. 'climbing jacket gender:unisex*' (I added a non-partial searching " in the version, iirc)
2. 'climbing jacket*'

I assume that it finds 3 more results partially on "jacket" (in query 2).

Currently, Picky still searches partially on the "gender:unisex" part – I will change this for the next version. Sorry for being so wobbly on this feature – it's still experimental, and needs to be refined iteratively. Thanks for helping me.
and may I suggest that uniq be incorporated into results#ids ?
ruby-1.9.3-p194 :051 > Product.query("climbing jacket",1000).ids.uniq.count
 => 22

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.

However, this is not yet passed into the queries when filtering facets (which I think, is not the way to go, as one wants a true result count for each facet).

I hope this helps.