picky 4.25.0 → 4.25.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d83031c692b720f4c0e208135d1a9132865f6db8
4
- data.tar.gz: da41d6d9de9c1762e83aee7c8bb3e62447e24934
3
+ metadata.gz: 44a3b70f33fe644a7c9ab0cc519af8c182cf09c3
4
+ data.tar.gz: e74d3117c847a410ef852ad9d850179327cd0b97
5
5
  SHA512:
6
- metadata.gz: f119107151b6848085eb65eb0cf1c52c4d30bcff59f05bf37c09599007f16d8394bec8fbdeecf0b80ae1465c75496789169055d84ff507f4be632fa21b085b32
7
- data.tar.gz: 9ab9540294fb221af016c379eff38486b96f9b0752428ed88e0dad44d60748de52f8d13c0172f99e2ebe503f82c6e81a053c130071efbeae6af315858ab6adf7
6
+ metadata.gz: d1da0628b51f4678f645d25dc637208ab508b580d1fbe33e7609538df2b322626cddd48bf85283b2f05ec374f1c37af16bf141d7421b7178a9ec6aa2f3bf067b
7
+ data.tar.gz: 2d28bbc6d9d95e11fd2829ad6d6695746ee3b273b298826420311eeb7005087c4c28cd3f5e10a9c3fb8fe143dbb857e231f685247f059d06c108c03948c16f4a
@@ -11,7 +11,7 @@ module Picky
11
11
  #
12
12
  class Token
13
13
 
14
- attr_reader :text, :original
14
+ attr_accessor :text, :original
15
15
  attr_writer :similar
16
16
  attr_writer :predefined_categories
17
17
 
@@ -40,7 +40,8 @@ module Picky
40
40
  # key_token = Query::Token.new ''
41
41
  # key_token.predefined_categories = [index[category_identifier]]
42
42
  #
43
- key_token = Query::Token.new '', nil, predefined_categories
43
+ empty = @symbol_keys ? :'' : ''
44
+ key_token = Query::Token.new empty, nil, predefined_categories
44
45
 
45
46
  # Pre-tokenize filter for reuse.
46
47
  #
@@ -55,9 +56,13 @@ module Picky
55
56
  # Get actual counts.
56
57
  #
57
58
  if no_counts
58
- facets_without_counts counts, minimal_counts, tokenized_filter_query, key_token.text, options
59
+ facets_without_counts counts, minimal_counts, tokenized_filter_query, options do |last_text|
60
+ key_token.text = last_text # TODO Why is this necessary?
61
+ end
59
62
  else
60
- facets_with_counts counts, minimal_counts, tokenized_filter_query, key_token.text, options
63
+ facets_with_counts counts, minimal_counts, tokenized_filter_query, key_token.text, options do |last_text|
64
+ key_token.text = last_text # TODO Why is this necessary?
65
+ end
61
66
  end
62
67
  end
63
68
  def facets_without_counts counts, minimal_counts, tokenized_filter_query, last_token_text, options = {}
@@ -66,7 +71,9 @@ module Picky
66
71
  # is the only information that changes in between
67
72
  # queries.
68
73
  #
69
- last_token_text.replace key
74
+ # Note: DOes not use replace anymore.
75
+ #
76
+ yield key
70
77
 
71
78
  # Calculate up to 1000 facets using unique to show correct facet counts.
72
79
  # TODO Redesign and deoptimize the whole process.
@@ -83,7 +90,7 @@ module Picky
83
90
  # is the only information that changes in between
84
91
  # queries.
85
92
  #
86
- last_token_text.replace key
93
+ yield key
87
94
 
88
95
  # Calculate up to 1000 facets using unique to show correct facet counts.
89
96
  # TODO Redesign and deoptimize the whole process.
@@ -226,4 +226,85 @@ describe 'facets' do
226
226
  end
227
227
 
228
228
  end
229
+
230
+ describe 'simple example with symbols' do
231
+ let(:index) {
232
+ index = Picky::Index.new :facets do
233
+ symbol_keys true
234
+ category :name, partial: Picky::Partial::Substring.new(from: 1)
235
+ category :surname
236
+ end
237
+
238
+ thing = Struct.new :id, :name, :surname
239
+ index.add thing.new(1, 'fritz', 'hanke')
240
+ index.add thing.new(2, 'kaspar', 'schiess')
241
+ index.add thing.new(3, 'florian', 'hanke')
242
+
243
+ index
244
+ }
245
+ let(:finder) do
246
+ Picky::Search.new(index) { symbol_keys }
247
+ end
248
+
249
+ describe 'Index#facets' do
250
+ it 'is correct' do
251
+ # Picky has 2 facets with different counts for surname.
252
+ #
253
+ index.facets(:surname).should == {
254
+ hanke: 2,
255
+ schiess: 1
256
+ }
257
+
258
+ # It has 3 facets with the same count for name.
259
+ #
260
+ index.facets(:name).should == {
261
+ fritz: 1,
262
+ kaspar: 1,
263
+ florian: 1
264
+ }
265
+
266
+ # Picky only selects facets with a count >= the given one.
267
+ #
268
+ index.facets(:surname, at_least: 2).should == {
269
+ hanke: 2
270
+ }
271
+ end
272
+ end
273
+
274
+ describe 'Search#facets' do
275
+ it 'filters them correctly' do
276
+ # Passing in no filter query just returns the facets
277
+ #
278
+ finder.facets(:surname).should == {
279
+ hanke: 2,
280
+ schiess: 1
281
+ }
282
+
283
+ # It has two facets.
284
+ #
285
+ finder.facets(:name, filter: 'surname:hanke').should == {
286
+ fritz: 1,
287
+ florian: 1
288
+ }
289
+
290
+ # It only uses exact matches (ie. the last token is not partialized).
291
+ #
292
+ finder.facets(:name, filter: 'surname:hank').should == {}
293
+
294
+ # It allows explicit partial matches.
295
+ #
296
+ finder.facets(:name, filter: 'surname:hank*').should == {
297
+ fritz: 1,
298
+ florian: 1
299
+ }
300
+
301
+ # It allows explicit partial matches.
302
+ #
303
+ finder.facets(:name, filter: 'surname:hank*').should == {
304
+ fritz: 1,
305
+ florian: 1
306
+ }
307
+ end
308
+ end
309
+ end
229
310
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.25.0
4
+ version: 4.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke