spec/functional/facets_spec.rb in picky-4.15.1 vs spec/functional/facets_spec.rb in picky-4.16.0

- old
+ new

@@ -187,7 +187,43 @@ it 'has 0 facets >= counts 2' do finder.facets(:surname, filter: 'age:40 name:peter', at_least: 2, counts: false).should == [] end end + describe 'Search#facets with identical category text/filter text' do + it 'does not report the same thing multiple times up to a limit' do + require 'picky' + + shoe = Struct.new(:id, :color, :name) + + shoes_index = Picky::Index.new(:shoes) do + category :color + category :name + end + + shoes_search = Picky::Search.new shoes_index + + shoes_index.add shoe.new(1, 'black', 'Outdoor Black') + + shoes_search.facets(:color).should == { 'black' => 1 } + shoes_search.facets(:color, filter: 'black').should == { 'black' => 1 } + + 999.times do |i| + shoes_index.add shoe.new(i+2, 'black', 'Outdoor Black') + end + + shoes_search.facets(:color).should == { 'black' => 1000 } + shoes_search.facets(:color, filter: 'black').should == { 'black' => 1000 } + + # But then, over 1000 the count is only a very rough estimate. + # + 500.times do |i| + shoes_index.add shoe.new(i+1001, 'black', 'Outdoor Black') + end + + shoes_search.facets(:color).should == { 'black' => 1500 } + shoes_search.facets(:color, filter: 'black').should == { 'black' => 2000 } + end + end + end end