picky 4.0.0pre2 → 4.0.0pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/aux/picky/cli.rb +1 -1
  2. data/lib/picky/backends/backend.rb +0 -16
  3. data/lib/picky/backends/file.rb +5 -10
  4. data/lib/picky/backends/memory.rb +5 -10
  5. data/lib/picky/backends/redis/basic.rb +3 -3
  6. data/lib/picky/backends/redis/list.rb +5 -6
  7. data/lib/picky/backends/redis/string.rb +1 -1
  8. data/lib/picky/backends/redis.rb +24 -27
  9. data/lib/picky/backends/sqlite/basic.rb +4 -4
  10. data/lib/picky/backends/sqlite.rb +7 -13
  11. data/lib/picky/bundle.rb +39 -43
  12. data/lib/picky/bundle_indexed.rb +17 -2
  13. data/lib/picky/bundle_indexing.rb +1 -26
  14. data/lib/picky/bundle_realtime.rb +2 -6
  15. data/lib/picky/category_indexing.rb +2 -2
  16. data/lib/picky/generators/similarity/phonetic.rb +3 -1
  17. data/lib/picky/index_indexing.rb +1 -1
  18. data/lib/picky/indexers/base.rb +5 -4
  19. data/lib/picky/indexers/parallel.rb +3 -3
  20. data/lib/picky/indexers/serial.rb +2 -2
  21. data/lib/picky/wrappers/bundle/location.rb +3 -5
  22. data/spec/functional/backends/redis_bundle_realtime_spec.rb +1 -1
  23. data/spec/functional/backends/redis_spec.rb +29 -6
  24. data/spec/functional/backends/special_spec.rb +229 -0
  25. data/spec/functional/backends/sqlite_bundle_realtime_spec.rb +1 -1
  26. data/spec/functional/backends/sqlite_spec.rb +1 -1
  27. data/spec/lib/backends/backend_spec.rb +40 -24
  28. data/spec/lib/backends/file_spec.rb +25 -25
  29. data/spec/lib/backends/memory_spec.rb +51 -51
  30. data/spec/lib/backends/redis_spec.rb +77 -77
  31. data/spec/lib/backends/sqlite/array_spec.rb +1 -1
  32. data/spec/lib/backends/sqlite_spec.rb +51 -51
  33. data/spec/lib/{indexed/bundle_spec.rb → bundle_indexed_spec.rb} +0 -0
  34. data/spec/lib/{indexing/bundle_spec.rb → bundle_indexing_spec.rb} +2 -9
  35. data/spec/lib/{indexing/bundle_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +0 -0
  36. data/spec/lib/{indexed/bundle_realtime_spec.rb → bundle_realtime_spec.rb} +0 -0
  37. data/spec/lib/category_indexed_spec.rb +2 -2
  38. data/spec/lib/category_spec.rb +2 -2
  39. data/spec/lib/extensions/object_spec.rb +8 -8
  40. data/spec/lib/generators/similarity/phonetic_spec.rb +13 -7
  41. data/spec/lib/index_spec.rb +16 -0
  42. data/spec/lib/indexers/base_spec.rb +1 -1
  43. metadata +27 -25
data/aux/picky/cli.rb CHANGED
@@ -104,7 +104,7 @@ module Picky
104
104
 
105
105
  # Maps commands to the other gem's command.
106
106
  #
107
- # TODO Try to load the other gems and get the commands dynamically.
107
+ # THINK Try to load the other gems and get the commands dynamically.
108
108
  #
109
109
  @@mapping = {
110
110
  :generate => [Generate, :'{client,server,all_in_one}', :'app_directory_name'],
@@ -6,22 +6,6 @@ module Picky
6
6
  #
7
7
  class Backend
8
8
 
9
- attr_reader :inverted,
10
- :weights,
11
- :similarity,
12
- :configuration
13
-
14
- def initialize options = {}
15
- @inverted = options[:inverted]
16
- @weights = options[:weights]
17
- @similarity = options[:similarity]
18
- @configuration = options[:configuration]
19
- end
20
-
21
- def extract_lambda_or thing, *args
22
- thing && (thing.respond_to?(:call) && thing.call(*args) || thing)
23
- end
24
-
25
9
  # Returns the total score of the combinations.
26
10
  #
27
11
  # Default implementation. Override to speed up.
@@ -14,36 +14,31 @@ module Picky
14
14
  # [:token] # => [id, id, id, id, id] (an array of ids)
15
15
  #
16
16
  def create_inverted bundle
17
- extract_lambda_or(inverted, bundle) ||
18
- JSON.new(bundle.index_path(:inverted))
17
+ JSON.new bundle.index_path(:inverted)
19
18
  end
20
19
  # Returns an object that on #initial, #load returns an object that responds to:
21
20
  # [:token] # => 1.23 (a weight)
22
21
  #
23
22
  def create_weights bundle
24
- extract_lambda_or(weights, bundle) ||
25
- JSON.new(bundle.index_path(:weights))
23
+ JSON.new bundle.index_path(:weights)
26
24
  end
27
25
  # Returns an object that on #initial, #load returns an object that responds to:
28
26
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
29
27
  #
30
28
  def create_similarity bundle
31
- extract_lambda_or(similarity, bundle) ||
32
- JSON.new(bundle.index_path(:similarity))
29
+ JSON.new bundle.index_path(:similarity)
33
30
  end
34
31
  # Returns an object that on #initial, #load returns an object that responds to:
35
32
  # [:key] # => value (a value for this config key)
36
33
  #
37
34
  def create_configuration bundle
38
- extract_lambda_or(configuration, bundle) ||
39
- JSON.new(bundle.index_path(:configuration))
35
+ JSON.new bundle.index_path(:configuration)
40
36
  end
41
37
  # Returns an object that on #initial, #load returns an object that responds to:
42
38
  # [id] # => [:sym1, :sym2]
43
39
  #
44
40
  def create_realtime bundle
45
- extract_lambda_or(similarity, bundle) ||
46
- JSON.new(bundle.index_path(:realtime))
41
+ JSON.new bundle.index_path(:realtime)
47
42
  end
48
43
 
49
44
  end
@@ -9,40 +9,35 @@ module Picky
9
9
  # [:token] # => [id, id, id, id, id] (an array of ids)
10
10
  #
11
11
  def create_inverted bundle
12
- extract_lambda_or(inverted, bundle) ||
13
- JSON.new(bundle.index_path(:inverted))
12
+ JSON.new bundle.index_path(:inverted)
14
13
  end
15
14
  # Returns an object that on #initial, #load returns
16
15
  # an object that responds to:
17
16
  # [:token] # => 1.23 (a weight)
18
17
  #
19
18
  def create_weights bundle
20
- extract_lambda_or(weights, bundle) ||
21
- JSON.new(bundle.index_path(:weights))
19
+ JSON.new bundle.index_path(:weights)
22
20
  end
23
21
  # Returns an object that on #initial, #load returns
24
22
  # an object that responds to:
25
23
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
26
24
  #
27
25
  def create_similarity bundle
28
- extract_lambda_or(similarity, bundle) ||
29
- Marshal.new(bundle.index_path(:similarity))
26
+ Marshal.new bundle.index_path(:similarity)
30
27
  end
31
28
  # Returns an object that on #initial, #load returns
32
29
  # an object that responds to:
33
30
  # [:key] # => value (a value for this config key)
34
31
  #
35
32
  def create_configuration bundle
36
- extract_lambda_or(configuration, bundle) ||
37
- JSON.new(bundle.index_path(:configuration))
33
+ JSON.new bundle.index_path(:configuration)
38
34
  end
39
35
  # Returns an object that on #initial, #load returns
40
36
  # an object that responds to:
41
37
  # [id] # => [:sym1, :sym2]
42
38
  #
43
39
  def create_realtime bundle
44
- extract_lambda_or(similarity, bundle) ||
45
- JSON.new(bundle.index_path(:realtime))
40
+ JSON.new bundle.index_path(:realtime)
46
41
  end
47
42
 
48
43
  end
@@ -24,14 +24,14 @@ module Picky
24
24
 
25
25
  @empty = options[:empty]
26
26
  @initial = options[:initial]
27
- @immediate = options[:immediate]
27
+ @realtime = options[:realtime]
28
28
  end
29
29
 
30
30
  # The empty index that is used for putting the index
31
31
  # together.
32
32
  #
33
33
  def empty
34
- @empty && @empty.clone || (@immediate ? self.reset : {})
34
+ @empty && @empty.clone || (@realtime ? self.reset : {})
35
35
  end
36
36
 
37
37
  # The initial content before loading.
@@ -40,7 +40,7 @@ module Picky
40
40
  # this just returns the same thing as #load.
41
41
  #
42
42
  def initial
43
- @initial && @initial.clone || (@immediate ? self.reset : {})
43
+ @initial && @initial.clone || (@realtime ? self.reset : {})
44
44
  end
45
45
 
46
46
  # Returns itself.
@@ -27,7 +27,7 @@ module Picky
27
27
  # Writes the hash into Redis.
28
28
  #
29
29
  def dump hash
30
- unless @immediate
30
+ unless @realtime
31
31
  clear
32
32
  # client.pipelined do
33
33
  hash.each_pair do |key, values|
@@ -54,9 +54,9 @@ module Picky
54
54
 
55
55
  # Set a single list.
56
56
  #
57
- # TODO Clear? Maybe only add the difference?
58
- #
59
57
  def []= key, values
58
+ delete key
59
+
60
60
  redis_key = "#{namespace}:#{key}"
61
61
  i = 0
62
62
  values.each do |value|
@@ -64,9 +64,8 @@ module Picky
64
64
  client.zadd redis_key, i, value
65
65
  end
66
66
 
67
- # We need to return the whole list.
68
- #
69
- self[key]
67
+ DirectlyManipulable.make self, values, key
68
+ values
70
69
  end
71
70
 
72
71
  end
@@ -23,7 +23,7 @@ module Picky
23
23
  # Note: We could use multi, but it did not help.
24
24
  #
25
25
  def dump hash
26
- unless @immediate
26
+ unless @realtime
27
27
  clear
28
28
  hash.each_pair do |key, value|
29
29
  client.hset namespace, key, value
@@ -7,17 +7,15 @@ module Picky
7
7
  class Redis < Backend
8
8
 
9
9
  attr_reader :client,
10
- :immediate
10
+ :realtime
11
11
 
12
12
  def initialize options = {}
13
- super options
14
-
15
13
  maybe_load_hiredis
16
14
  check_hiredis_gem
17
15
  check_redis_gem
18
16
 
19
17
  @client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
20
- @immediate = options[:immediate]
18
+ @realtime = options[:realtime]
21
19
  end
22
20
  def maybe_load_hiredis
23
21
  require 'hiredis'
@@ -39,36 +37,31 @@ module Picky
39
37
  # [:token] # => [id, id, id, id, id] (an array of ids)
40
38
  #
41
39
  def create_inverted bundle
42
- extract_lambda_or(inverted, bundle, client) ||
43
- List.new(client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:inverted", immediate: immediate)
40
+ List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:inverted", realtime: realtime
44
41
  end
45
42
  # Returns an object that on #initial, #load returns an object that responds to:
46
43
  # [:token] # => 1.23 (a weight)
47
44
  #
48
45
  def create_weights bundle
49
- extract_lambda_or(weights, bundle, client) ||
50
- Float.new(client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:weights", immediate: immediate)
46
+ Float.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:weights", realtime: realtime
51
47
  end
52
48
  # Returns an object that on #initial, #load returns an object that responds to:
53
49
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
54
50
  #
55
51
  def create_similarity bundle
56
- extract_lambda_or(similarity, bundle, client) ||
57
- List.new(client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:similarity", immediate: immediate)
52
+ List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:similarity", realtime: realtime
58
53
  end
59
54
  # Returns an object that on #initial, #load returns an object that responds to:
60
55
  # [:key] # => value (a value for this config key)
61
56
  #
62
57
  def create_configuration bundle
63
- extract_lambda_or(configuration, bundle, client) ||
64
- String.new(client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:configuration", immediate: immediate)
58
+ String.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:configuration", realtime: realtime
65
59
  end
66
60
  # Returns an object that on #initial, #load returns an object that responds to:
67
61
  # [id] # => [:sym1, :sym2]
68
62
  #
69
63
  def create_realtime bundle
70
- extract_lambda_or(similarity, bundle) ||
71
- List.new(client, "#{bundle.identifier}:realtime", immediate: immediate)
64
+ List.new client, "#{bundle.identifier}:realtime", realtime: realtime
72
65
  end
73
66
 
74
67
  # Does the Redis version already include
@@ -162,12 +155,12 @@ module Picky
162
155
  # Note: We use the amount and offset hints to speed Redis up.
163
156
  #
164
157
  def ids combinations, amount, offset
165
- # TODO FIXME This is actually not correct:
166
- # A dumped/loaded Redis backend should use
167
- # the Redis backend calculation method.
168
- # So loaded? would be more appropriate.
158
+ # TODO This is actually not correct:
159
+ # A dumped/loaded Redis backend should use
160
+ # the Redis backend calculation method.
161
+ # So loaded? would be more appropriate.
169
162
  #
170
- if immediate
163
+ if realtime
171
164
  # Just checked once on the first call.
172
165
  #
173
166
  if redis_with_scripting?
@@ -187,12 +180,18 @@ module Picky
187
180
  # Assume it's using EVALSHA.
188
181
  #
189
182
  begin
190
- client.evalsha @@ids_sent_once,
191
- identifiers.size,
192
- *identifiers,
193
- generate_intermediate_result_id,
194
- offset,
195
- (offset + amount)
183
+ if identifiers.size > 1
184
+ client.evalsha @@ids_sent_once,
185
+ identifiers.size,
186
+ *identifiers,
187
+ generate_intermediate_result_id,
188
+ offset,
189
+ (offset + amount)
190
+ else
191
+ client.zrange identifiers.first,
192
+ offset,
193
+ (offset + amount)
194
+ end
196
195
  rescue RuntimeError => e
197
196
  # Make the server have a SHA-1 for the script.
198
197
  #
@@ -219,8 +218,6 @@ module Picky
219
218
 
220
219
  # Little optimization.
221
220
  #
222
- # TODO Include in the scripting version as well.
223
- #
224
221
  if identifiers.size > 1
225
222
  # Intersect and store.
226
223
  #
@@ -14,21 +14,21 @@ module Picky
14
14
  @cache_path = "#{cache_path}.sqlite3"
15
15
  @empty = options[:empty]
16
16
  @initial = options[:initial]
17
- @self_indexed = options[:self_indexed]
17
+ @realtime = options[:realtime]
18
18
 
19
19
  lazily_initialize_client
20
20
  end
21
21
 
22
22
  def initial
23
- @initial && @initial.clone || (@self_indexed ? self.reset : {})
23
+ @initial && @initial.clone || (@realtime ? self.reset : {})
24
24
  end
25
25
 
26
26
  def empty
27
- @empty && @empty.clone || (@self_indexed ? self.reset.asynchronous : {})
27
+ @empty && @empty.clone || (@realtime ? self.reset.asynchronous : {})
28
28
  end
29
29
 
30
30
  def dump internal
31
- dump_sqlite internal unless @self_indexed
31
+ dump_sqlite internal unless @realtime
32
32
  self
33
33
  end
34
34
 
@@ -4,11 +4,10 @@ module Picky
4
4
 
5
5
  class SQLite < Backend
6
6
 
7
- attr_reader :self_indexed
7
+ attr_reader :realtime
8
8
 
9
9
  def initialize options = {}
10
- super options
11
- @self_indexed = options[:self_indexed]
10
+ @realtime = options[:realtime]
12
11
 
13
12
  require 'sqlite3'
14
13
  rescue LoadError => e
@@ -19,36 +18,31 @@ module Picky
19
18
  # [:token] # => [id, id, id, id, id] (an array of ids)
20
19
  #
21
20
  def create_inverted bundle
22
- extract_lambda_or(inverted, bundle) ||
23
- StringKeyArray.new(bundle.index_path(:inverted), self_indexed: self_indexed)
21
+ StringKeyArray.new bundle.index_path(:inverted), realtime: realtime
24
22
  end
25
23
  # Returns an object that on #initial, #load returns an object that responds to:
26
24
  # [:token] # => 1.23 (a weight)
27
25
  #
28
26
  def create_weights bundle
29
- extract_lambda_or(weights, bundle) ||
30
- Value.new(bundle.index_path(:weights), self_indexed: self_indexed)
27
+ Value.new bundle.index_path(:weights), realtime: realtime
31
28
  end
32
29
  # Returns an object that on #initial, #load returns an object that responds to:
33
30
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
34
31
  #
35
32
  def create_similarity bundle
36
- extract_lambda_or(similarity, bundle) ||
37
- StringKeyArray.new(bundle.index_path(:similarity), self_indexed: self_indexed)
33
+ StringKeyArray.new bundle.index_path(:similarity), realtime: realtime
38
34
  end
39
35
  # Returns an object that on #initial, #load returns an object that responds to:
40
36
  # [:key] # => value (a value for this config key)
41
37
  #
42
38
  def create_configuration bundle
43
- extract_lambda_or(configuration, bundle) ||
44
- Value.new(bundle.index_path(:configuration), self_indexed: self_indexed)
39
+ Value.new bundle.index_path(:configuration), realtime: realtime
45
40
  end
46
41
  # Returns an object that on #initial, #load returns an object that responds to:
47
42
  # [id] # => [:sym1, :sym2]
48
43
  #
49
44
  def create_realtime bundle
50
- extract_lambda_or(similarity, bundle) ||
51
- IntegerKeyArray.new(bundle.index_path(:realtime), self_indexed: self_indexed)
45
+ IntegerKeyArray.new bundle.index_path(:realtime), realtime: realtime
52
46
  end
53
47
 
54
48
  end
data/lib/picky/bundle.rb CHANGED
@@ -35,19 +35,20 @@ module Picky
35
35
  :backend_weights,
36
36
  :backend_similarity,
37
37
  :backend_configuration,
38
+ :backend_realtime,
38
39
 
39
- :weights_strategy,
40
+ :weight_strategy,
40
41
  :partial_strategy,
41
42
  :similarity_strategy
42
43
 
43
44
  delegate :[], :[]=, :to => :configuration
44
45
  delegate :index_directory, :to => :category
45
46
 
46
- def initialize name, category, weights_strategy, partial_strategy, similarity_strategy, options = {}
47
+ def initialize name, category, weight_strategy, partial_strategy, similarity_strategy, options = {}
47
48
  @name = name
48
49
  @category = category
49
50
 
50
- @weights_strategy = weights_strategy
51
+ @weight_strategy = weight_strategy
51
52
  @partial_strategy = partial_strategy
52
53
  @similarity_strategy = similarity_strategy
53
54
 
@@ -70,21 +71,31 @@ module Picky
70
71
  # Initializes all necessary indexes from the backend.
71
72
  #
72
73
  def reset_backend
73
- # Extract specific indexes from backend.
74
- #
75
- @backend_inverted = backend.create_inverted self
76
- @backend_weights = backend.create_weights self
77
- @backend_similarity = backend.create_similarity self
74
+ create_backends
75
+ initialize_backends
76
+ end
77
+
78
+ # Extract specific indexes from backend.
79
+ #
80
+ def create_backends
81
+ @backend_inverted = backend.create_inverted self
82
+ @backend_weights = backend.create_weights self
83
+ @backend_similarity = backend.create_similarity self
78
84
  @backend_configuration = backend.create_configuration self
79
- @backend_realtime = backend.create_realtime self
85
+ @backend_realtime = backend.create_realtime self
86
+ end
80
87
 
81
- # Initial indexes.
82
- #
83
- # Note that if the weights strategy doesn't need to be saved,
84
- # the strategy itself pretends to be an index.
85
- #
88
+ # Initial indexes.
89
+ #
90
+ # Note that if the weights strategy doesn't need to be saved,
91
+ # the strategy itself pretends to be an index.
92
+ #
93
+ def initialize_backends
94
+ # @inverted, @weights, @similarity, @configuration, @realtime = backend.initial weight_strategy
86
95
  @inverted = @backend_inverted.initial
87
- @weights = @weights_strategy.saved?? @backend_weights.initial : @weights_strategy
96
+ # TODO @weights = @weight_strategy.initial || @backend_weights.initial
97
+ #
98
+ @weights = @weight_strategy.saved?? @backend_weights.initial : @weight_strategy
88
99
  @similarity = @backend_similarity.initial
89
100
  @configuration = @backend_configuration.initial
90
101
  @realtime = @backend_realtime.initial
@@ -94,30 +105,27 @@ module Picky
94
105
  # internal backend instance.
95
106
  #
96
107
  def empty
97
- empty_inverted
98
- empty_weights
99
- empty_similarity
100
- empty_configuration
101
- empty_realtime
102
- end
103
- def empty_inverted
104
108
  @inverted = @backend_inverted.empty
105
- end
106
- def empty_weights
107
109
  # THINK about this. Perhaps the strategies should implement the backend methods?
108
110
  #
109
- @weights = @weights_strategy.saved?? @backend_weights.empty : @weights_strategy
110
- end
111
- def empty_similarity
111
+ @weights = @weight_strategy.saved? ? @backend_weights.empty : @weight_strategy
112
112
  @similarity = @backend_similarity.empty
113
- end
114
- def empty_configuration
115
113
  @configuration = @backend_configuration.empty
116
- end
117
- def empty_realtime
118
114
  @realtime = @backend_realtime.empty
119
115
  end
120
116
 
117
+ # Delete all index files.
118
+ #
119
+ def delete
120
+ @backend_inverted.delete if @backend_inverted.respond_to? :delete
121
+ # THINK about this. Perhaps the strategies should implement the backend methods?
122
+ #
123
+ @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weight_strategy.saved?
124
+ @backend_similarity.delete if @backend_similarity.respond_to? :delete
125
+ @backend_configuration.delete if @backend_configuration.respond_to? :delete
126
+ @backend_realtime.delete if @backend_realtime.respond_to? :delete
127
+ end
128
+
121
129
  # Get a list of similar texts.
122
130
  #
123
131
  # Note: Does not return itself.
@@ -156,18 +164,6 @@ module Picky
156
164
  ::File.join index_directory, "#{category.name}_#{name}#{ "_#{type}" if type }"
157
165
  end
158
166
 
159
- # Delete all index files.
160
- #
161
- def delete
162
- @backend_inverted.delete if @backend_inverted.respond_to? :delete
163
- # THINK about this. Perhaps the strategies should implement the backend methods?
164
- #
165
- @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weights_strategy.saved?
166
- @backend_similarity.delete if @backend_similarity.respond_to? :delete
167
- @backend_configuration.delete if @backend_configuration.respond_to? :delete
168
- @backend_realtime.delete if @backend_realtime.respond_to? :delete
169
- end
170
-
171
167
  def to_s
172
168
  "#{self.class}(#{identifier})"
173
169
  end
@@ -25,6 +25,21 @@ module Picky
25
25
  #
26
26
  def ids sym_or_string
27
27
  @inverted[sym_or_string] || []
28
+ # TODO ?
29
+ #
30
+ # if @key_format
31
+ # class << self
32
+ # def ids
33
+ # (@inverted[sym_or_string] || []).map &@key_format
34
+ # end
35
+ # end
36
+ # else
37
+ # class << self
38
+ # def ids
39
+ # @inverted[sym_or_string] || []
40
+ # end
41
+ # end
42
+ # end
28
43
  end
29
44
 
30
45
  # Get a weight for the given symbol.
@@ -64,9 +79,9 @@ module Picky
64
79
  # Loads the weights index.
65
80
  #
66
81
  def load_weights
67
- # THINK about this. Perhaps the strategies should implement the backend methods?
82
+ # TODO @weights = @weight_strategy.load || @backend_weights.load
68
83
  #
69
- self.weights = @backend_weights.load if @weights_strategy.saved?
84
+ self.weights = @backend_weights.load if @weight_strategy.saved?
70
85
  end
71
86
  # Loads the similarity index.
72
87
  #
@@ -31,37 +31,12 @@ module Picky
31
31
  # Saves the indexes in a dump file.
32
32
  #
33
33
  def dump
34
- dump_inverted
35
- dump_similarity
36
- dump_weights
37
- dump_configuration
38
- dump_realtime
39
- end
40
- # Dumps the core index.
41
- #
42
- def dump_inverted
43
34
  @backend_inverted.dump @inverted
44
- end
45
- # Dumps the weights index.
46
- #
47
- def dump_weights
48
35
  # THINK about this. Perhaps the strategies should implement the backend methods? Or only the internal index ones?
49
36
  #
50
- @backend_weights.dump @weights if @weights_strategy.saved?
51
- end
52
- # Dumps the similarity index.
53
- #
54
- def dump_similarity
37
+ @backend_weights.dump @weights if @weight_strategy.saved?
55
38
  @backend_similarity.dump @similarity if @similarity_strategy.saved?
56
- end
57
- # Dumps the configuration.
58
- #
59
- def dump_configuration
60
39
  @backend_configuration.dump @configuration
61
- end
62
- # Dumps the realtime.
63
- #
64
- def dump_realtime
65
40
  @backend_realtime.dump @realtime
66
41
  end
67
42
 
@@ -24,7 +24,7 @@ module Picky
24
24
  #
25
25
  @similarity.delete self.similarity_strategy.encoded(str_or_sym)
26
26
  else
27
- @weights[str_or_sym] = self.weights_strategy.weight_for ids.size
27
+ @weights[str_or_sym] = self.weight_strategy.weight_for ids.size
28
28
  end
29
29
  end
30
30
 
@@ -53,7 +53,7 @@ module Picky
53
53
 
54
54
  # Weights.
55
55
  #
56
- @weights[str_or_sym] = self.weights_strategy.weight_for ids.size
56
+ @weights[str_or_sym] = self.weight_strategy.weight_for ids.size
57
57
 
58
58
  # Similarity.
59
59
  #
@@ -74,10 +74,6 @@ module Picky
74
74
  #
75
75
  similars.delete str_or_sym if similars.include? str_or_sym
76
76
  similars << str_or_sym
77
-
78
- # Uses the sort order of the strategy.
79
- #
80
- self.similarity_strategy.sort similars, str_or_sym
81
77
  end
82
78
  end
83
79
 
@@ -31,7 +31,7 @@ module Picky
31
31
  with_data_snapshot do
32
32
  scheduler.schedule do
33
33
  indexer.prepare categories, scheduler
34
- nil # TODO Needed so procrastinate is happy. Remove in 4.0.
34
+ nil # Note: Needed so procrastinate is happy.
35
35
  end
36
36
  end
37
37
  end
@@ -43,7 +43,7 @@ module Picky
43
43
  empty
44
44
  retrieve
45
45
  dump
46
- nil # TODO Needed so procrastinate is happy. Remove in 4.0.
46
+ nil # Note: Needed so procrastinate is happy.
47
47
  end
48
48
  end
49
49
 
@@ -36,7 +36,9 @@ module Picky
36
36
 
37
37
  # Sorts the index values in place.
38
38
  #
39
- def sort ary, code
39
+ # Not used currently.
40
+ #
41
+ def prioritize! ary, code
40
42
  ary.sort_by_levenshtein! code
41
43
  ary.slice! amount, ary.size # THINK size is not perfectly correct, but anyway
42
44
  end
@@ -105,7 +105,7 @@ module Picky
105
105
  # capsule, i.e. a block/lambda.
106
106
  #
107
107
  def extract_source
108
- @source = @source.respond_to?(:call) ? @source.call : @source
108
+ @source.respond_to?(:call) ? @source.call : @source
109
109
  end
110
110
  def check_source source # :nodoc:
111
111
  raise ArgumentError.new(<<-SOURCE