picky 4.15.1 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2MxMTQxZjI1MDcwYzA1N2UzNWY2MTQ5ZGNkMTllYWFjYmI1MDk0Nw==
4
+ NjVkMTA4OTYyYzkyZTMzZjAxYjM3YWRlMGQwMGE2MDc4Zjc3NDA4Nw==
5
5
  data.tar.gz: !binary |-
6
- NjA3MTc5MTEwMWUzZWQ1NGZjNWU0ZjRhZDJmMTJhZjhhYjdiZWIzNA==
6
+ NDBiYmEzNWJlNDE3OTNkMmVhODU3NWYyY2QyZTQ4ZTdiN2RmZTA5Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjdhYmYyYTkwOGJlZmUzZjljYTA2MjIxNzg0NWEwYzZkZWE2ZmE3OTdmZGEz
10
- Mjc4YjYwMWZlMTU4Zjk0NGQyNGE4NzM2MjA0ZWY2MGRkODlhM2Y5Y2ZhYWZk
11
- MzFjOWM2ZTQ4MzQzYTFiYTA3ZjUyZmQyZTU1NGU0ZjExMGQyYTA=
9
+ YmQ3MzczYTdmZjFlOTMwYmQ3ZjY3ZTkwMzBiMjU2MTUzMGQyZmM1ZjNkODg2
10
+ NGFjMTc0NzQ3MDRiZGQ3ZjY1ZGY3MzNlYjMyY2FkNTJmZWNlMzg2YWE0NWEx
11
+ Njk5NWQzYmI2OWVmMWM0NTMyZTliZGUwMTE2NDdmZWI4NzVlMGQ=
12
12
  data.tar.gz: !binary |-
13
- MzlhODU0NmZlNGRkOGM4YzlkZDY3MTQxYmJlYTA2MWJkYWEwMGI4MjEwNzA1
14
- M2VhYjExNzQ2YzdhODcyZjE0ZWVlN2QzMDRmNTU0YTI0YjVjMjFkNzc1ODk2
15
- ZjQ3OTQyNTVhNmY3ZjhiN2ZhZWY4MWM0OTcyMDYxYjIzMTQ1YTY=
13
+ NGRmYmE3OTMxOTE0NmY3OTY2NThhMTdhNDI1YzQ5OTQ3ZDhlZjhmNjEzMmEw
14
+ NjcyNGIyYTVjYjdkNzU3NTFhNTZkN2M1YzdiMDBiOWNlMmQ5YTBmZDFiMjRk
15
+ MTFkZGIwOThmNmEzOTRjODRlMDVlMzYyMTEyYjI5ZTcwOTkwYTA=
@@ -45,11 +45,10 @@ module Picky
45
45
  # Note: Returns [] if no categories matched (will produce no result).
46
46
  #
47
47
  def possible_for token, preselected_categories = nil
48
- possible = (preselected_categories || possible_categories(token)).inject([]) do |combinations, category|
48
+ (preselected_categories || possible_categories(token)).inject([]) do |combinations, category|
49
49
  combination = category.combination_for token
50
50
  combination ? combinations << combination : combinations
51
51
  end
52
- possible
53
52
  end
54
53
 
55
54
  # This returns the possible categories for this token.
@@ -16,6 +16,8 @@ module Picky
16
16
  # Adds and indexes this category of the
17
17
  # given object.
18
18
  #
19
+ # TODO Don't do this super-dynamically.
20
+ #
19
21
  def add object, where = :unshift
20
22
  if from.respond_to? :call
21
23
  add_text object.id, from.call(object), where
@@ -53,32 +53,40 @@ module Picky
53
53
  # Get actual counts.
54
54
  #
55
55
  if no_counts
56
- facets_without_counts counts, minimal_counts, tokenized_filter_query, key_token.text
56
+ facets_without_counts counts, minimal_counts, tokenized_filter_query, key_token.text, options
57
57
  else
58
- facets_with_counts counts, minimal_counts, tokenized_filter_query, key_token.text
58
+ facets_with_counts counts, minimal_counts, tokenized_filter_query, key_token.text, options
59
59
  end
60
60
  end
61
- def facets_without_counts counts, minimal_counts, tokenized_filter_query, last_token_text
61
+ def facets_without_counts counts, minimal_counts, tokenized_filter_query, last_token_text, options = {}
62
62
  counts.inject([]) do |result, (key, _)|
63
63
  # Replace only the key token text because that
64
64
  # is the only information that changes in between
65
65
  # queries.
66
66
  #
67
67
  last_token_text.replace key
68
- total = search_with(tokenized_filter_query, 0, 0).total
68
+
69
+ # Calculate up to 1000 facets using unique to show correct facet counts.
70
+ # TODO Redesign and deoptimize the whole process.
71
+ #
72
+ total = search_with(tokenized_filter_query, 1000, 0, nil, true).total
69
73
 
70
74
  next result unless total >= minimal_counts
71
75
  result << key
72
76
  end
73
77
  end
74
- def facets_with_counts counts, minimal_counts, tokenized_filter_query, last_token_text
78
+ def facets_with_counts counts, minimal_counts, tokenized_filter_query, last_token_text, options = {}
75
79
  counts.inject({}) do |result, (key, _)|
76
80
  # Replace only the key token text because that
77
81
  # is the only information that changes in between
78
82
  # queries.
79
83
  #
80
84
  last_token_text.replace key
81
- total = search_with(tokenized_filter_query, 0, 0).total
85
+
86
+ # Calculate up to 1000 facets using unique to show correct facet counts.
87
+ # TODO Redesign and deoptimize the whole process.
88
+ #
89
+ total = search_with(tokenized_filter_query, 1000, 0, nil, true).total
82
90
 
83
91
  next result unless total >= minimal_counts
84
92
  result[key] = total
@@ -189,5 +189,41 @@ describe 'facets' do
189
189
  end
190
190
  end
191
191
 
192
+ describe 'Search#facets with identical category text/filter text' do
193
+ it 'does not report the same thing multiple times up to a limit' do
194
+ require 'picky'
195
+
196
+ shoe = Struct.new(:id, :color, :name)
197
+
198
+ shoes_index = Picky::Index.new(:shoes) do
199
+ category :color
200
+ category :name
201
+ end
202
+
203
+ shoes_search = Picky::Search.new shoes_index
204
+
205
+ shoes_index.add shoe.new(1, 'black', 'Outdoor Black')
206
+
207
+ shoes_search.facets(:color).should == { 'black' => 1 }
208
+ shoes_search.facets(:color, filter: 'black').should == { 'black' => 1 }
209
+
210
+ 999.times do |i|
211
+ shoes_index.add shoe.new(i+2, 'black', 'Outdoor Black')
212
+ end
213
+
214
+ shoes_search.facets(:color).should == { 'black' => 1000 }
215
+ shoes_search.facets(:color, filter: 'black').should == { 'black' => 1000 }
216
+
217
+ # But then, over 1000 the count is only a very rough estimate.
218
+ #
219
+ 500.times do |i|
220
+ shoes_index.add shoe.new(i+1001, 'black', 'Outdoor Black')
221
+ end
222
+
223
+ shoes_search.facets(:color).should == { 'black' => 1500 }
224
+ shoes_search.facets(:color, filter: 'black').should == { 'black' => 2000 }
225
+ end
226
+ end
227
+
192
228
  end
193
229
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.15.1
4
+ version: 4.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-13 00:00:00.000000000 Z
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 4.15.1
47
+ version: 4.16.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 4.15.1
54
+ version: 4.16.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: text
57
57
  requirement: !ruby/object:Gem::Requirement