picky 3.2.0 → 3.3.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.
Files changed (85) hide show
  1. data/aux/picky/cli.rb +3 -1
  2. data/lib/picky/backends/backend.rb +16 -0
  3. data/lib/picky/backends/file/basic.rb +18 -9
  4. data/lib/picky/backends/file/json.rb +1 -0
  5. data/lib/picky/backends/file.rb +8 -4
  6. data/lib/picky/backends/helpers/file.rb +6 -0
  7. data/lib/picky/backends/memory/basic.rb +10 -2
  8. data/lib/picky/backends/memory/json.rb +1 -6
  9. data/lib/picky/backends/memory/marshal.rb +1 -6
  10. data/lib/picky/backends/memory/text.rb +1 -0
  11. data/lib/picky/backends/memory.rb +8 -4
  12. data/lib/picky/backends/redis/basic.rb +12 -9
  13. data/lib/picky/backends/redis.rb +10 -4
  14. data/lib/picky/bundle.rb +14 -0
  15. data/lib/picky/bundle_indexed.rb +110 -0
  16. data/lib/picky/bundle_indexing.rb +177 -0
  17. data/lib/picky/bundle_realtime.rb +80 -0
  18. data/lib/picky/categories.rb +5 -1
  19. data/lib/picky/category.rb +12 -20
  20. data/lib/picky/category_indexed.rb +3 -6
  21. data/lib/picky/category_indexing.rb +19 -18
  22. data/lib/picky/category_realtime.rb +5 -10
  23. data/lib/picky/extensions/symbol.rb +1 -1
  24. data/lib/picky/generators/partial/default.rb +1 -1
  25. data/lib/picky/generators/partial/postfix.rb +30 -0
  26. data/lib/picky/generators/partial/substring.rb +8 -2
  27. data/lib/picky/index.rb +3 -3
  28. data/lib/picky/index_indexing.rb +3 -2
  29. data/lib/picky/indexers/base.rb +0 -8
  30. data/lib/picky/indexers/parallel.rb +1 -1
  31. data/lib/picky/loader.rb +15 -15
  32. data/lib/picky/query/qualifier_category_mapper.rb +1 -1
  33. data/lib/picky/rack/harakiri.rb +3 -1
  34. data/lib/picky/sources/db.rb +11 -0
  35. data/lib/picky/statistics.rb +2 -2
  36. data/lib/picky/tokenizer.rb +1 -1
  37. data/lib/picky/tokenizers/location.rb +1 -1
  38. data/lib/picky/wrappers/bundle/calculation.rb +45 -0
  39. data/lib/picky/wrappers/bundle/delegators.rb +69 -0
  40. data/lib/picky/wrappers/bundle/exact_partial.rb +38 -0
  41. data/lib/picky/{indexed/wrappers → wrappers}/bundle/location.rb +6 -4
  42. data/lib/picky/wrappers/bundle/wrapper.rb +29 -0
  43. data/lib/picky/wrappers/category/exact_first.rb +55 -0
  44. data/lib/picky/wrappers/category/location.rb +33 -0
  45. data/lib/picky/{sources/wrappers → wrappers/sources}/base.rb +7 -3
  46. data/lib/picky/{sources/wrappers → wrappers/sources}/location.rb +3 -3
  47. data/lib/picky.rb +10 -11
  48. data/spec/aux/picky/cli_spec.rb +5 -5
  49. data/spec/lib/backends/backend_spec.rb +39 -0
  50. data/spec/lib/backends/file/basic_spec.rb +59 -0
  51. data/spec/lib/backends/file_spec.rb +105 -0
  52. data/spec/lib/backends/memory/basic_spec.rb +43 -15
  53. data/spec/lib/backends/memory_spec.rb +108 -54
  54. data/spec/lib/backends/redis/basic_spec.rb +81 -57
  55. data/spec/lib/backends/redis_spec.rb +120 -66
  56. data/spec/lib/category_indexed_spec.rb +12 -12
  57. data/spec/lib/category_indexing_spec.rb +23 -23
  58. data/spec/lib/category_spec.rb +14 -14
  59. data/spec/lib/cores_spec.rb +2 -2
  60. data/spec/lib/extensions/object_spec.rb +7 -7
  61. data/spec/lib/generators/partial/postfix_spec.rb +131 -0
  62. data/spec/lib/generators/partial/substring_spec.rb +29 -4
  63. data/spec/lib/generators/weights_generator_spec.rb +3 -3
  64. data/spec/lib/index_indexing_spec.rb +11 -15
  65. data/spec/lib/index_spec.rb +8 -8
  66. data/spec/lib/indexed/bundle_realtime_spec.rb +18 -18
  67. data/spec/lib/indexed/bundle_spec.rb +21 -21
  68. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +9 -9
  69. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +8 -8
  70. data/spec/lib/indexed/wrappers/exact_first_spec.rb +16 -16
  71. data/spec/lib/indexers/base_spec.rb +6 -25
  72. data/spec/lib/indexes_spec.rb +33 -22
  73. data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +2 -2
  74. data/spec/lib/indexing/bundle_spec.rb +27 -28
  75. data/spec/lib/sources/wrappers/base_spec.rb +7 -7
  76. data/spec/lib/sources/wrappers/location_spec.rb +8 -8
  77. metadata +48 -38
  78. data/lib/picky/indexed/bundle.rb +0 -125
  79. data/lib/picky/indexed/bundle_realtime.rb +0 -76
  80. data/lib/picky/indexed/wrappers/bundle/calculation.rb +0 -47
  81. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +0 -47
  82. data/lib/picky/indexed/wrappers/category/location.rb +0 -31
  83. data/lib/picky/indexed/wrappers/exact_first.rb +0 -59
  84. data/lib/picky/indexing/bundle.rb +0 -183
  85. data/lib/picky/indexing/wrappers/category/location.rb +0 -29
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Sources::Wrappers::Location do
4
-
3
+ describe Picky::Wrappers::Sources::Location do
4
+
5
5
  context "with backend" do
6
6
  before(:each) do
7
7
  @source = stub :source
@@ -20,20 +20,20 @@ describe Picky::Sources::Wrappers::Location do
20
20
  @wrapper.calculation.precision.should == 1
21
21
  end
22
22
  it "delegates harvest" do
23
- @category.stub! :indexing_exact => {}
24
-
23
+ @category.stub! :exact => {}
24
+
25
25
  @source.should_receive(:harvest).once.with @category
26
-
26
+
27
27
  @wrapper.harvest @category
28
28
  end
29
29
  it "delegates take_snapshot" do
30
30
  @source.should_receive(:take_snapshot).once.with()
31
-
31
+
32
32
  @wrapper.take_snapshot
33
33
  end
34
34
  it "delegates connect_backend" do
35
35
  @source.should_receive(:connect_backend).once.with()
36
-
36
+
37
37
  @wrapper.connect_backend
38
38
  end
39
39
  end
@@ -51,5 +51,5 @@ describe Picky::Sources::Wrappers::Location do
51
51
  lambda { described_class.new }.should raise_error(ArgumentError)
52
52
  end
53
53
  end
54
-
54
+
55
55
  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: 3.2.0
4
+ version: 3.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2011-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70313421431340 !ruby/object:Gem::Requirement
16
+ requirement: &70120341880280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70313421431340
24
+ version_requirements: *70120341880280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70313421430840 !ruby/object:Gem::Requirement
27
+ requirement: &70120341879500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
31
31
  - !ruby/object:Gem::Version
32
- version: 3.2.0
32
+ version: 3.3.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70313421430840
35
+ version_requirements: *70120341879500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack
38
- requirement: &70313421430420 !ruby/object:Gem::Requirement
38
+ requirement: &70120341861000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70313421430420
46
+ version_requirements: *70120341861000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack_fast_escape
49
- requirement: &70313421429920 !ruby/object:Gem::Requirement
49
+ requirement: &70120341860060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70313421429920
57
+ version_requirements: *70120341860060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: text
60
- requirement: &70313421429420 !ruby/object:Gem::Requirement
60
+ requirement: &70120341859480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70313421429420
68
+ version_requirements: *70120341859480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
- requirement: &70313421428860 !ruby/object:Gem::Requirement
71
+ requirement: &70120341858820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70313421428860
79
+ version_requirements: *70120341858820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &70313421427820 !ruby/object:Gem::Requirement
82
+ requirement: &70120341857900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70313421427820
90
+ version_requirements: *70120341857900
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &70313421443700 !ruby/object:Gem::Requirement
93
+ requirement: &70120341857140 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '3.0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70313421443700
101
+ version_requirements: *70120341857140
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: unicorn
104
- requirement: &70313421443320 !ruby/object:Gem::Requirement
104
+ requirement: &70120341856560 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70313421443320
112
+ version_requirements: *70120341856560
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sinatra
115
- requirement: &70313421442840 !ruby/object:Gem::Requirement
115
+ requirement: &70120341855740 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70313421442840
123
+ version_requirements: *70120341855740
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: redis
126
- requirement: &70313421442420 !ruby/object:Gem::Requirement
126
+ requirement: &70120341854880 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70313421442420
134
+ version_requirements: *70120341854880
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mysql
137
- requirement: &70313421441980 !ruby/object:Gem::Requirement
137
+ requirement: &70120341853680 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *70313421441980
145
+ version_requirements: *70120341853680
146
146
  description: Fast Ruby semantic text search engine with comfortable single field interface.
147
147
  email: florian.hanke+picky@gmail.com
148
148
  executables:
@@ -174,6 +174,9 @@ files:
174
174
  - lib/picky/backends/redis/string.rb
175
175
  - lib/picky/backends/redis.rb
176
176
  - lib/picky/bundle.rb
177
+ - lib/picky/bundle_indexed.rb
178
+ - lib/picky/bundle_indexing.rb
179
+ - lib/picky/bundle_realtime.rb
177
180
  - lib/picky/bundling.rb
178
181
  - lib/picky/calculations/location.rb
179
182
  - lib/picky/categories.rb
@@ -202,6 +205,7 @@ files:
202
205
  - lib/picky/generators/partial/default.rb
203
206
  - lib/picky/generators/partial/infix.rb
204
207
  - lib/picky/generators/partial/none.rb
208
+ - lib/picky/generators/partial/postfix.rb
205
209
  - lib/picky/generators/partial/strategy.rb
206
210
  - lib/picky/generators/partial/substring.rb
207
211
  - lib/picky/generators/partial_generator.rb
@@ -223,21 +227,12 @@ files:
223
227
  - lib/picky/index_indexed.rb
224
228
  - lib/picky/index_indexing.rb
225
229
  - lib/picky/index_realtime.rb
226
- - lib/picky/indexed/bundle.rb
227
- - lib/picky/indexed/bundle_realtime.rb
228
- - lib/picky/indexed/wrappers/bundle/calculation.rb
229
- - lib/picky/indexed/wrappers/bundle/location.rb
230
- - lib/picky/indexed/wrappers/bundle/wrapper.rb
231
- - lib/picky/indexed/wrappers/category/location.rb
232
- - lib/picky/indexed/wrappers/exact_first.rb
233
230
  - lib/picky/indexers/base.rb
234
231
  - lib/picky/indexers/parallel.rb
235
232
  - lib/picky/indexers/serial.rb
236
233
  - lib/picky/indexes.rb
237
234
  - lib/picky/indexes_indexed.rb
238
235
  - lib/picky/indexes_indexing.rb
239
- - lib/picky/indexing/bundle.rb
240
- - lib/picky/indexing/wrappers/category/location.rb
241
236
  - lib/picky/interfaces/live_parameters.rb
242
237
  - lib/picky/loader.rb
243
238
  - lib/picky/migrations/from_30_to_31.rb
@@ -263,12 +258,19 @@ files:
263
258
  - lib/picky/sources/db.rb
264
259
  - lib/picky/sources/delicious.rb
265
260
  - lib/picky/sources/mongo.rb
266
- - lib/picky/sources/wrappers/base.rb
267
- - lib/picky/sources/wrappers/location.rb
268
261
  - lib/picky/statistics.rb
269
262
  - lib/picky/tasks.rb
270
263
  - lib/picky/tokenizer.rb
271
264
  - lib/picky/tokenizers/location.rb
265
+ - lib/picky/wrappers/bundle/calculation.rb
266
+ - lib/picky/wrappers/bundle/delegators.rb
267
+ - lib/picky/wrappers/bundle/exact_partial.rb
268
+ - lib/picky/wrappers/bundle/location.rb
269
+ - lib/picky/wrappers/bundle/wrapper.rb
270
+ - lib/picky/wrappers/category/exact_first.rb
271
+ - lib/picky/wrappers/category/location.rb
272
+ - lib/picky/wrappers/sources/base.rb
273
+ - lib/picky/wrappers/sources/location.rb
272
274
  - lib/picky.rb
273
275
  - lib/tasks/try.rb
274
276
  - lib/tasks/application.rake
@@ -288,6 +290,9 @@ files:
288
290
  - spec/lib/adapters/rack/query_spec.rb
289
291
  - spec/lib/analyzer_spec.rb
290
292
  - spec/lib/application_spec.rb
293
+ - spec/lib/backends/backend_spec.rb
294
+ - spec/lib/backends/file/basic_spec.rb
295
+ - spec/lib/backends/file_spec.rb
291
296
  - spec/lib/backends/memory/basic_spec.rb
292
297
  - spec/lib/backends/memory/json_spec.rb
293
298
  - spec/lib/backends/memory/marshal_spec.rb
@@ -318,6 +323,7 @@ files:
318
323
  - spec/lib/generators/partial/default_spec.rb
319
324
  - spec/lib/generators/partial/infix_spec.rb
320
325
  - spec/lib/generators/partial/none_spec.rb
326
+ - spec/lib/generators/partial/postfix_spec.rb
321
327
  - spec/lib/generators/partial/substring_spec.rb
322
328
  - spec/lib/generators/partial_generator_spec.rb
323
329
  - spec/lib/generators/similarity/double_metaphone_spec.rb
@@ -410,6 +416,9 @@ test_files:
410
416
  - spec/lib/adapters/rack/query_spec.rb
411
417
  - spec/lib/analyzer_spec.rb
412
418
  - spec/lib/application_spec.rb
419
+ - spec/lib/backends/backend_spec.rb
420
+ - spec/lib/backends/file/basic_spec.rb
421
+ - spec/lib/backends/file_spec.rb
413
422
  - spec/lib/backends/memory/basic_spec.rb
414
423
  - spec/lib/backends/memory/json_spec.rb
415
424
  - spec/lib/backends/memory/marshal_spec.rb
@@ -440,6 +449,7 @@ test_files:
440
449
  - spec/lib/generators/partial/default_spec.rb
441
450
  - spec/lib/generators/partial/infix_spec.rb
442
451
  - spec/lib/generators/partial/none_spec.rb
452
+ - spec/lib/generators/partial/postfix_spec.rb
443
453
  - spec/lib/generators/partial/substring_spec.rb
444
454
  - spec/lib/generators/partial_generator_spec.rb
445
455
  - spec/lib/generators/similarity/double_metaphone_spec.rb
@@ -1,125 +0,0 @@
1
- module Picky
2
-
3
- module Indexed # :nodoc:all
4
-
5
- # An indexed bundle is a number of memory/redis
6
- # indexes that compose the indexes for a single category:
7
- # * core (inverted) index
8
- # * weights index
9
- # * similarity index
10
- # * index configuration
11
- #
12
- # Indexed refers to them being indexed.
13
- # This class notably offers the methods:
14
- # * load
15
- # * clear
16
- #
17
- # To (re)load or clear the current indexes.
18
- #
19
- class Bundle < Picky::Bundle
20
-
21
- attr_reader :realtime_mapping
22
-
23
- def initialize name, category, backend, weights_strategy, partial_strategy, similarity_strategy, options = {}
24
- super name, category, backend, weights_strategy, partial_strategy, similarity_strategy, options
25
-
26
- @inverted = @backend_inverted.initial
27
- @weights = @backend_weights.initial
28
- @similarity = @backend_similarity.initial
29
- @configuration = @backend_configuration.initial
30
-
31
- @realtime_mapping = {} # id -> ary of syms. TODO Always instantiate?
32
- end
33
-
34
- # Get the ids for the given symbol.
35
- #
36
- # Returns a (potentially empty) array of ids.
37
- #
38
- def ids sym
39
- @inverted[sym] || []
40
- end
41
-
42
- # Get a weight for the given symbol.
43
- #
44
- # Returns a number, or nil.
45
- #
46
- def weight sym
47
- @weights[sym]
48
- end
49
-
50
- # Get settings for this bundle.
51
- #
52
- # Returns an object.
53
- #
54
- def [] sym
55
- @configuration[sym]
56
- end
57
-
58
- # Loads all indexes.
59
- #
60
- # Loading loads index objects from the backend.
61
- # They should each respond to [] and return something appropriate.
62
- #
63
- def load
64
- load_inverted
65
- load_weights
66
- load_similarity
67
- load_configuration
68
- end
69
-
70
- # Loads the core index.
71
- #
72
- def load_inverted
73
- self.inverted = @backend_inverted.load
74
- end
75
- # Loads the weights index.
76
- #
77
- def load_weights
78
- self.weights = @backend_weights.load
79
- end
80
- # Loads the similarity index.
81
- #
82
- def load_similarity
83
- self.similarity = @backend_similarity.load
84
- end
85
- # Loads the configuration.
86
- #
87
- def load_configuration
88
- self.configuration = @backend_configuration.load
89
- end
90
-
91
- # Clears all indexes.
92
- #
93
- def clear
94
- clear_inverted
95
- clear_weights
96
- clear_similarity
97
- clear_configuration
98
- end
99
-
100
- # Clears the core index.
101
- #
102
- def clear_inverted
103
- inverted.clear
104
- end
105
- # Clears the weights index.
106
- #
107
- def clear_weights
108
- weights.clear
109
- end
110
- # Clears the similarity index.
111
- #
112
- def clear_similarity
113
- similarity.clear
114
- end
115
- # Clears the configuration.
116
- #
117
- def clear_configuration
118
- configuration.clear
119
- end
120
-
121
- end
122
-
123
- end
124
-
125
- end
@@ -1,76 +0,0 @@
1
- module Picky
2
-
3
- module Indexed # :nodoc:all
4
-
5
- class Bundle < Picky::Bundle
6
-
7
- # Removes the given id from the indexes.
8
- #
9
- def remove id
10
- # Is it anywhere?
11
- #
12
- syms = @realtime_mapping[id]
13
- return unless syms
14
-
15
- syms.each do |sym|
16
- ids = @inverted[sym]
17
- ids.delete id
18
-
19
- encoded = self.similarity_strategy.encoded sym
20
-
21
- if ids.empty?
22
- @inverted.delete sym
23
- @weights.delete sym
24
- # Since no element uses this sym anymore, we can delete the similarity for it.
25
- # TODO Not really. Since multiple syms can point to the same encoded.
26
- @similarity.delete encoded
27
- else
28
- @weights[sym] = self.weights_strategy.weight_for ids.size
29
- end
30
- end
31
-
32
- @realtime_mapping.delete id
33
- end
34
-
35
- # Returns a reference to the array where the id has been added.
36
- #
37
- def add id, sym
38
- ary = @inverted[sym]
39
-
40
- syms = @realtime_mapping[id]
41
- syms = (@realtime_mapping[id] = []) unless syms # TODO Nicefy.
42
-
43
- # Inverted.
44
- #
45
- ids = if syms.include? sym
46
- ids = @inverted[sym]
47
- ids.delete id # Move id
48
- ids.unshift id # to front
49
- else
50
- syms << sym
51
- inverted = @inverted[sym] ||= []
52
- inverted.unshift id
53
- end
54
-
55
- # Weights.
56
- #
57
- @weights[sym] = self.weights_strategy.weight_for ids.size
58
-
59
- # Similarity.
60
- #
61
- if encoded = self.similarity_strategy.encoded(sym)
62
- similarity = @similarity[encoded] ||= []
63
- if similarity.include? sym
64
- similarity.delete sym # Not completely correct, as others will also be affected, but meh.
65
- similarity.unshift sym #
66
- else
67
- similarity.unshift sym
68
- end
69
- end
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,47 +0,0 @@
1
- module Picky
2
-
3
- module Indexed
4
- module Wrappers
5
-
6
- module Bundle
7
-
8
- # A calculation rewrites the symbol into a float.
9
- #
10
- # Note: A calculation will try to find a float in the index,
11
- # not a sym.
12
- #
13
- # TODO I really need to allow integers as keys.
14
- # The code below is just not up to the needed quality.
15
- # Use key_format :to_i?
16
- #
17
- class Calculation < Wrapper
18
-
19
- # API.
20
- #
21
- # By default, a calculation does not
22
- # recalculate anything.
23
- #
24
- def recalculate float
25
- float
26
- end
27
-
28
- #
29
- #
30
- def ids float_as_sym
31
- @bundle.ids recalculate(float_as_sym.to_s.to_f).to_s.to_sym
32
- end
33
-
34
- #
35
- #
36
- def weight float_as_sym
37
- @bundle.weight recalculate(float_as_sym.to_s.to_f).to_s.to_sym
38
- end
39
-
40
- end
41
-
42
- end
43
-
44
- end
45
- end
46
-
47
- end
@@ -1,47 +0,0 @@
1
- module Picky
2
-
3
- module Indexed
4
- module Wrappers
5
-
6
- # Per Bundle wrappers.
7
- #
8
- module Bundle
9
-
10
- # Base wrapper. Just delegates all methods to the bundle.
11
- #
12
- class Wrapper
13
-
14
- attr_reader :bundle
15
-
16
- def initialize bundle
17
- @bundle = bundle
18
- end
19
-
20
- delegate :load,
21
- :load_inverted,
22
- :load_weights,
23
- :load_similarity,
24
- :load_configuration,
25
- :clear_inverted,
26
- :clear_weights,
27
- :clear_similarity,
28
- :clear_configuration,
29
- :ids,
30
- :weight,
31
- :identifier,
32
- :analyze,
33
- :size,
34
- :inverted,
35
- :weights,
36
- :similarity,
37
- :configuration,
38
- :to => :@bundle
39
-
40
- end
41
-
42
- end
43
-
44
- end
45
- end
46
-
47
- end
@@ -1,31 +0,0 @@
1
- module Picky
2
-
3
- module Indexed
4
- module Wrappers
5
- module Category
6
-
7
- module Location
8
-
9
- # THINK Is this the best way to do this?
10
- #
11
- def self.install_on category, grid, precision = 1
12
- wrapped_exact = Indexed::Wrappers::Bundle::Location.new category.indexed_exact, grid: grid, precision: precision
13
-
14
- category.class_eval do
15
- define_method :indexed_exact do
16
- wrapped_exact
17
- end
18
- define_method :indexed_partial do
19
- wrapped_exact
20
- end
21
- end
22
-
23
- end
24
-
25
- end
26
-
27
- end
28
- end
29
- end
30
-
31
- end
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- module Picky
4
-
5
- module Indexed
6
-
7
- module Wrappers
8
-
9
- # This index combines an exact and partial index.
10
- # It serves to order the results such that exact hits are found first.
11
- #
12
- class ExactFirst < Indexed::Bundle
13
-
14
- delegate :similar,
15
- :identifier,
16
- :name,
17
- :to => :@exact
18
- delegate :index,
19
- :category,
20
- :weight,
21
- :generate_partial_from,
22
- :generate_caches_from_memory,
23
- :generate_derived,
24
- :dump,
25
- :load,
26
- :to => :@partial
27
-
28
- def initialize category
29
- @exact = category.indexed_exact
30
- @partial = category.indexed_partial
31
- end
32
-
33
- def self.wrap index_or_category
34
- if index_or_category.respond_to? :categories
35
- wrap_each_of index_or_category.categories
36
- index_or_category
37
- else
38
- new index_or_category
39
- end
40
- end
41
- def self.wrap_each_of categories
42
- categories.categories.collect! { |category| new(category) }
43
- end
44
-
45
- def ids text
46
- @exact.ids(text) + @partial.ids(text)
47
- end
48
-
49
- def weight text
50
- [@exact.weight(text) || 0, @partial.weight(text) || 0].max
51
- end
52
-
53
- end
54
-
55
- end
56
-
57
- end
58
-
59
- end