picky 3.5.4 → 3.6.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 (57) hide show
  1. data/lib/picky/backends/backend.rb +1 -1
  2. data/lib/picky/backends/file/basic.rb +0 -36
  3. data/lib/picky/backends/file/json.rb +1 -1
  4. data/lib/picky/backends/file.rb +4 -4
  5. data/lib/picky/backends/helpers/file.rb +0 -26
  6. data/lib/picky/backends/memory/basic.rb +0 -35
  7. data/lib/picky/backends/memory.rb +4 -4
  8. data/lib/picky/backends/redis/basic.rb +0 -33
  9. data/lib/picky/backends/redis.rb +4 -4
  10. data/lib/picky/backends/sqlite/db.rb +84 -0
  11. data/lib/picky/backends/sqlite.rb +75 -0
  12. data/lib/picky/bundle.rb +15 -87
  13. data/lib/picky/bundle_realtime.rb +1 -1
  14. data/lib/picky/categories.rb +1 -0
  15. data/lib/picky/categories_indexed.rb +1 -1
  16. data/lib/picky/categories_indexing.rb +1 -3
  17. data/lib/picky/category.rb +16 -2
  18. data/lib/picky/category_indexed.rb +5 -3
  19. data/lib/picky/category_indexing.rb +0 -26
  20. data/lib/picky/category_realtime.rb +2 -0
  21. data/lib/picky/extensions/string.rb +20 -0
  22. data/lib/picky/extensions/symbol.rb +22 -0
  23. data/lib/picky/generators/similarity/double_metaphone.rb +1 -2
  24. data/lib/picky/generators/similarity/metaphone.rb +1 -2
  25. data/lib/picky/generators/similarity/phonetic.rb +0 -10
  26. data/lib/picky/generators/similarity/soundex.rb +1 -2
  27. data/lib/picky/index.rb +9 -2
  28. data/lib/picky/index_indexed.rb +4 -4
  29. data/lib/picky/index_indexing.rb +1 -5
  30. data/lib/picky/indexes_indexed.rb +7 -6
  31. data/lib/picky/indexes_indexing.rb +1 -7
  32. data/lib/picky/loader.rb +4 -1
  33. data/lib/picky/sources/couch.rb +1 -1
  34. data/lib/picky/sources/mongo.rb +1 -1
  35. data/lib/picky/wrappers/bundle/calculation.rb +1 -1
  36. data/lib/picky/wrappers/bundle/exact_partial.rb +3 -12
  37. data/lib/picky/wrappers/bundle/location.rb +1 -0
  38. data/lib/tasks/index.rake +0 -4
  39. data/spec/lib/backends/file/basic_spec.rb +5 -17
  40. data/spec/lib/backends/memory/basic_spec.rb +5 -17
  41. data/spec/lib/backends/redis/basic_spec.rb +5 -52
  42. data/spec/lib/backends/sqlite/db_spec.rb +80 -0
  43. data/spec/lib/backends/sqlite_spec.rb +131 -0
  44. data/spec/lib/category_indexed_spec.rb +2 -2
  45. data/spec/lib/category_indexing_spec.rb +0 -24
  46. data/spec/lib/extensions/string_spec.rb +16 -0
  47. data/spec/lib/extensions/symbol_spec.rb +16 -0
  48. data/spec/lib/index_indexed_spec.rb +16 -16
  49. data/spec/lib/indexes_indexed_spec.rb +13 -7
  50. data/spec/lib/indexes_indexing_spec.rb +3 -6
  51. data/spec/lib/indexing/bundle_spec.rb +6 -125
  52. data/spec/lib/sources/couch_spec.rb +8 -8
  53. data/spec/lib/sources/mongo_spec.rb +5 -5
  54. data/spec/specific/realtime_spec.rb +397 -173
  55. metadata +44 -29
  56. data/lib/picky/bundling.rb +0 -10
  57. data/lib/tasks/checks.rake +0 -13
@@ -23,7 +23,7 @@ module Picky
23
23
  #
24
24
  #
25
25
  def to_s
26
- "#{self.class}(#{[inverted, weights, similarity, configuration].join(', ')})"
26
+ self.class.name
27
27
  end
28
28
 
29
29
  end
@@ -55,26 +55,6 @@ module Picky
55
55
  @initial && @initial.clone || nil
56
56
  end
57
57
 
58
- # Will copy the index file to a location that
59
- # is in a directory named "backup" right under
60
- # the directory the index file is in.
61
- #
62
- def backup
63
- mapping_file.backup
64
-
65
- prepare_backup backup_directory(cache_path)
66
- FileUtils.cp cache_path, target, verbose: true
67
- end
68
-
69
- # Copies the file from its backup location back
70
- # to the original location.
71
- #
72
- def restore
73
- mapping_file.restore
74
-
75
- FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true
76
- end
77
-
78
58
  # Deletes the file.
79
59
  #
80
60
  def delete
@@ -83,22 +63,6 @@ module Picky
83
63
  `rm -Rf #{cache_path}`
84
64
  end
85
65
 
86
- # Is this cache file suspiciously small?
87
- # (less than 8 Bytes of size)
88
- #
89
- def cache_small?
90
- size_of(cache_path) < 8
91
- end
92
-
93
- # Is the cache ok? (existing and larger than
94
- # zero Bytes in size)
95
- #
96
- # A small cache is still ok.
97
- #
98
- def cache_ok?
99
- size_of(cache_path) > 0
100
- end
101
-
102
66
  #
103
67
  #
104
68
  def to_s
@@ -84,4 +84,4 @@ module Picky
84
84
 
85
85
  end
86
86
 
87
- end
87
+ end
@@ -15,28 +15,28 @@ module Picky
15
15
  #
16
16
  def create_inverted bundle
17
17
  extract_lambda_or(inverted, bundle) ||
18
- JSON.new(bundle.index_path(:inverted))
18
+ JSON.new(bundle.index_path(:inverted))
19
19
  end
20
20
  # Returns an object that on #initial, #load returns an object that responds to:
21
21
  # [:token] # => 1.23 (a weight)
22
22
  #
23
23
  def create_weights bundle
24
24
  extract_lambda_or(weights, bundle) ||
25
- JSON.new(bundle.index_path(:weights))
25
+ JSON.new(bundle.index_path(:weights))
26
26
  end
27
27
  # Returns an object that on #initial, #load returns an object that responds to:
28
28
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
29
29
  #
30
30
  def create_similarity bundle
31
31
  extract_lambda_or(similarity, bundle) ||
32
- JSON.new(bundle.index_path(:similarity))
32
+ JSON.new(bundle.index_path(:similarity))
33
33
  end
34
34
  # Returns an object that on #initial, #load returns an object that responds to:
35
35
  # [:key] # => value (a value for this config key)
36
36
  #
37
37
  def create_configuration bundle
38
38
  extract_lambda_or(configuration, bundle) ||
39
- JSON.new(bundle.index_path(:configuration))
39
+ JSON.new(bundle.index_path(:configuration))
40
40
  end
41
41
 
42
42
  # Currently, the loaded ids are intersected using
@@ -14,32 +14,6 @@ module Picky
14
14
  FileUtils.mkdir_p ::File.dirname(path)
15
15
  end
16
16
 
17
- # The backup directory of this file.
18
- # Equal to the file's dirname plus /backup
19
- #
20
- def backup_directory path
21
- ::File.join ::File.dirname(path), 'backup'
22
- end
23
-
24
- # Prepares the backup directory for the file.
25
- #
26
- def prepare_backup target
27
- FileUtils.mkdir target unless Dir.exists?(target)
28
- end
29
-
30
- # The backup filename.
31
- #
32
- def backup_file_path_of path
33
- dir, name = ::File.split path
34
- ::File.join dir, 'backup', name
35
- end
36
-
37
- # Extracts the size of the file in Bytes.
38
- #
39
- def size_of path
40
- `ls -l #{path} | awk '{print $5}'`.to_i
41
- end
42
-
43
17
  end
44
18
 
45
19
  end
@@ -47,47 +47,12 @@ module Picky
47
47
  @initial && @initial.clone || {}
48
48
  end
49
49
 
50
- # Will copy the index file to a location that
51
- # is in a directory named "backup" right under
52
- # the directory the index file is in.
53
- #
54
- def backup
55
- prepare_backup backup_directory
56
- FileUtils.cp cache_path, target, verbose: true
57
- end
58
-
59
- # Copies the file from its backup location back
60
- # to the original location.
61
- #
62
- def restore
63
- FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true
64
- end
65
-
66
50
  # Deletes the file.
67
51
  #
68
52
  def delete
69
53
  `rm -Rf #{cache_path}`
70
54
  end
71
55
 
72
- # Checks.
73
- #
74
-
75
- # Is this cache file suspiciously small?
76
- # (less than 8 Bytes of size)
77
- #
78
- def cache_small?
79
- size_of(cache_path) < 8
80
- end
81
-
82
- # Is the cache ok? (existing and larger than
83
- # zero Bytes in size)
84
- #
85
- # A small cache is still ok.
86
- #
87
- def cache_ok?
88
- size_of(cache_path) > 0
89
- end
90
-
91
56
  #
92
57
  #
93
58
  def to_s
@@ -9,28 +9,28 @@ module Picky
9
9
  #
10
10
  def create_inverted bundle
11
11
  extract_lambda_or(inverted, bundle) ||
12
- JSON.new(bundle.index_path(:inverted))
12
+ JSON.new(bundle.index_path(:inverted))
13
13
  end
14
14
  # Returns an object that on #initial, #load returns an object that responds to:
15
15
  # [:token] # => 1.23 (a weight)
16
16
  #
17
17
  def create_weights bundle
18
18
  extract_lambda_or(weights, bundle) ||
19
- JSON.new(bundle.index_path(:weights))
19
+ JSON.new(bundle.index_path(:weights))
20
20
  end
21
21
  # Returns an object that on #initial, #load returns an object that responds to:
22
22
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
23
23
  #
24
24
  def create_similarity bundle
25
25
  extract_lambda_or(similarity, bundle) ||
26
- Marshal.new(bundle.index_path(:similarity))
26
+ Marshal.new(bundle.index_path(:similarity))
27
27
  end
28
28
  # Returns an object that on #initial, #load returns an object that responds to:
29
29
  # [:key] # => value (a value for this config key)
30
30
  #
31
31
  def create_configuration bundle
32
32
  extract_lambda_or(configuration, bundle) ||
33
- JSON.new(bundle.index_path(:configuration))
33
+ JSON.new(bundle.index_path(:configuration))
34
34
  end
35
35
 
36
36
  # Returns the result ids for the allocation.
@@ -54,12 +54,6 @@ module Picky
54
54
  # Nothing.
55
55
  end
56
56
 
57
- # Redis doesn't do backup.
58
- #
59
- def backup
60
- # Nothing.
61
- end
62
-
63
57
  # Deletes the Redis index namespace.
64
58
  #
65
59
  def delete
@@ -69,33 +63,6 @@ module Picky
69
63
  # we don't do anything.
70
64
  end
71
65
 
72
- # Checks.
73
- #
74
-
75
- # Is this cache suspiciously small?
76
- #
77
- def cache_small?
78
- size < 1
79
- end
80
-
81
- # Is the cache ok?
82
- #
83
- # A small cache is still ok.
84
- #
85
- def cache_ok?
86
- size > 0
87
- end
88
-
89
- # Extracts the size of the file in Bytes.
90
- #
91
- # Note: This is a very forgiving implementation.
92
- # But as long as Redis does not implement
93
- # DBSIZE KEYPATTERN, we are stuck with this.
94
- #
95
- def size
96
- client.dbsize
97
- end
98
-
99
66
  #
100
67
  #
101
68
  def to_s
@@ -22,28 +22,28 @@ module Picky
22
22
  #
23
23
  def create_inverted bundle
24
24
  extract_lambda_or(inverted, bundle, client) ||
25
- List.new(client, "#{bundle.identifier}:inverted")
25
+ List.new(client, "#{bundle.identifier}:inverted")
26
26
  end
27
27
  # Returns an object that on #initial, #load returns an object that responds to:
28
28
  # [:token] # => 1.23 (a weight)
29
29
  #
30
30
  def create_weights bundle
31
31
  extract_lambda_or(weights, bundle, client) ||
32
- Float.new(client, "#{bundle.identifier}:weights")
32
+ Float.new(client, "#{bundle.identifier}:weights")
33
33
  end
34
34
  # Returns an object that on #initial, #load returns an object that responds to:
35
35
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
36
36
  #
37
37
  def create_similarity bundle
38
38
  extract_lambda_or(similarity, bundle, client) ||
39
- List.new(client, "#{bundle.identifier}:similarity")
39
+ List.new(client, "#{bundle.identifier}:similarity")
40
40
  end
41
41
  # Returns an object that on #initial, #load returns an object that responds to:
42
42
  # [:key] # => value (a value for this config key)
43
43
  #
44
44
  def create_configuration bundle
45
45
  extract_lambda_or(configuration, bundle, client) ||
46
- String.new(client, "#{bundle.identifier}:configuration")
46
+ String.new(client, "#{bundle.identifier}:configuration")
47
47
  end
48
48
 
49
49
  # Does the Redis version already include
@@ -0,0 +1,84 @@
1
+ module Picky
2
+
3
+ module Backends
4
+
5
+ class Sqlite
6
+
7
+ class DB
8
+
9
+ include Helpers::File
10
+
11
+ attr_reader :cache_path, :db
12
+
13
+ def initialize cache_path, options = {}
14
+ @cache_path = "#{cache_path}.sqlite3"
15
+ @empty = options[:empty]
16
+ @initial = options[:initial]
17
+ end
18
+
19
+ def initial
20
+ @initial && @initial.clone || {}
21
+ end
22
+
23
+ def empty
24
+ @empty && @empty.clone || {}
25
+ end
26
+
27
+ def lazily_initialize_client
28
+ @db ||= SQLite3::Database.new cache_path
29
+ end
30
+
31
+ def dump_sqlite internal
32
+ lazily_initialize_client
33
+
34
+ # TODO Does it make a difference if these
35
+ # statements are given as one to the
36
+ # @db.execute method?
37
+ #
38
+
39
+ db.execute 'drop table if exists key_value;'
40
+ db.execute 'create table key_value (key varchar(255), value text);'
41
+ db.execute 'create index key_idx on key_value (key);'
42
+ db.execute 'BEGIN;'
43
+
44
+ # Note: Internal structures need to
45
+ # implement each.
46
+ #
47
+ internal.each do |key, value|
48
+ encoded_value = Yajl::Encoder.encode value
49
+ db.execute 'insert into key_value values (?,?)', key.to_s, encoded_value
50
+ end
51
+
52
+ db.execute 'COMMIT;'
53
+ end
54
+
55
+ def dump internal
56
+ create_directory cache_path
57
+ dump_sqlite internal
58
+ end
59
+
60
+ def load
61
+ lazily_initialize_client
62
+ self
63
+ end
64
+
65
+ def [] key
66
+ res = db.execute "select value from key_value where key = ? limit 1;", key.to_s
67
+ return nil if res.empty?
68
+
69
+ # TODO Slightly speed up by not calling Yajl for the || case?
70
+ #
71
+ Yajl::Parser.parse res.first.first || ""
72
+ end
73
+
74
+ def to_s
75
+ "#{self.class}(#{cache_path})"
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,75 @@
1
+ module Picky
2
+
3
+ module Backends
4
+
5
+ class Sqlite < Backend
6
+
7
+ def initialize options = {}
8
+ super options
9
+
10
+ require 'sqlite3'
11
+ rescue LoadError => e
12
+ warn_gem_missing 'sqlite3', 'SQLite bindings'
13
+ end
14
+
15
+ # Returns an object that on #initial, #load returns an object that responds to:
16
+ # [:token] # => [id, id, id, id, id] (an array of ids)
17
+ #
18
+ def create_inverted bundle
19
+ extract_lambda_or(inverted, bundle) ||
20
+ DB.new(bundle.index_path(:inverted))
21
+ end
22
+ # Returns an object that on #initial, #load returns an object that responds to:
23
+ # [:token] # => 1.23 (a weight)
24
+ #
25
+ def create_weights bundle
26
+ extract_lambda_or(weights, bundle) ||
27
+ DB.new(bundle.index_path(:weights))
28
+ end
29
+ # Returns an object that on #initial, #load returns an object that responds to:
30
+ # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
31
+ #
32
+ def create_similarity bundle
33
+ extract_lambda_or(similarity, bundle) ||
34
+ DB.new(bundle.index_path(:similarity))
35
+ end
36
+ # Returns an object that on #initial, #load returns an object that responds to:
37
+ # [:key] # => value (a value for this config key)
38
+ #
39
+ def create_configuration bundle
40
+ extract_lambda_or(configuration, bundle) ||
41
+ DB.new(bundle.index_path(:configuration))
42
+ end
43
+
44
+ # Returns the result ids for the allocation.
45
+ #
46
+ # Sorts the ids by size and & through them in the following order (sizes):
47
+ # 0. [100_000, 400, 30, 2]
48
+ # 1. [2, 30, 400, 100_000]
49
+ # 2. (100_000 & (400 & (30 & 2))) # => result
50
+ #
51
+ # Note: Uses a C-optimized intersection routine (in performant.c)
52
+ # for speed and memory efficiency.
53
+ #
54
+ # Note: In the memory based version we ignore the amount and offset hints.
55
+ # We cannot use the information to speed up the algorithm, unfortunately.
56
+ #
57
+ def ids combinations, _, _
58
+ # Get the ids for each combination.
59
+ #
60
+ id_arrays = combinations.inject([]) do |total, combination|
61
+ total << combination.ids
62
+ end
63
+
64
+ # Call the optimized C algorithm.
65
+ #
66
+ # Note: It orders the passed arrays by size.
67
+ #
68
+ Performant::Array.memory_efficient_intersect id_arrays
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
data/lib/picky/bundle.rb CHANGED
@@ -55,6 +55,19 @@ module Picky
55
55
  @partial_strategy = partial_strategy
56
56
  @similarity_strategy = similarity_strategy
57
57
 
58
+ reset_backend backend
59
+ end
60
+ def identifier
61
+ "#{category.identifier}:#{name}"
62
+ end
63
+
64
+ # Resets the backend with the given one instantly.
65
+ #
66
+ # TODO Redesign such that the backend is only
67
+ # generated lazily.
68
+ # And reset using backend = nil.
69
+ #
70
+ def reset_backend backend
58
71
  # Extract specific indexes from backend.
59
72
  #
60
73
  # TODO Clean up all related.
@@ -74,10 +87,7 @@ module Picky
74
87
  @similarity = @backend_similarity.initial
75
88
  @configuration = @backend_configuration.initial
76
89
 
77
- @realtime_mapping = {} # id -> ary of syms. TODO Always instantiate?
78
- end
79
- def identifier
80
- "#{category.identifier}:#{name}"
90
+ @realtime_mapping = {} # id -> ary of syms. TODO Always instantiate? d
81
91
  end
82
92
 
83
93
  # "Empties" the index(es) by getting a new empty
@@ -136,99 +146,17 @@ module Picky
136
146
  ::File.join index_directory, "#{category.name}_#{name}#{ "_#{type}" if type }"
137
147
  end
138
148
 
139
- # Copies the indexes to the "backup" directory.
140
- #
141
- def backup
142
- @backend_inverted.backup if @backend_inverted.respond_to? :backup
143
- # TODO THINK about this. Perhaps the strategies should implement the backend methods?
144
- #
145
- @backend_weights.backup if @backend_weights.respond_to? :backup && @weights_strategy.saved?
146
- @backend_similarity.backup if @backend_similarity.respond_to? :backup
147
- @backend_configuration.backup if @backend_configuration.respond_to? :backup
148
- end
149
-
150
- # Restores the indexes from the "backup" directory.
151
- #
152
- def restore
153
- @backend_inverted.restore if @backend_inverted.respond_to? :restore
154
- # TODO THINK about this. Perhaps the strategies should implement the backend methods?
155
- #
156
- @backend_weights.restore if @backend_weights.respond_to? :restore && @weights_strategy.saved?
157
- @backend_similarity.restore if @backend_similarity.respond_to? :restore
158
- @backend_configuration.restore if @backend_configuration.respond_to? :restore
159
- end
160
-
161
149
  # Delete all index files.
162
150
  #
163
151
  def delete
164
152
  @backend_inverted.delete if @backend_inverted.respond_to? :delete
165
153
  # TODO THINK about this. Perhaps the strategies should implement the backend methods?
166
154
  #
167
- @backend_weights.delete if @backend_weights.respond_to? :delete && @weights_strategy.saved?
155
+ @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weights_strategy.saved?
168
156
  @backend_similarity.delete if @backend_similarity.respond_to? :delete
169
157
  @backend_configuration.delete if @backend_configuration.respond_to? :delete
170
158
  end
171
159
 
172
- # Alerts the user if an index is missing.
173
- #
174
- def raise_unless_cache_exists
175
- raise_unless_index_exists
176
- raise_unless_similarity_exists
177
- end
178
- # Alerts the user if one of the necessary indexes
179
- # (core, weights) is missing.
180
- #
181
- def raise_unless_index_exists
182
- if partial_strategy.saved?
183
- warn_if_index_small
184
- raise_unless_index_ok
185
- end
186
- end
187
- # Alerts the user if the similarity
188
- # index is missing (given that it's used).
189
- #
190
- def raise_unless_similarity_exists
191
- if similarity_strategy.saved?
192
- warn_if_similarity_small
193
- raise_unless_similarity_ok
194
- end
195
- end
196
-
197
- # Outputs a warning for the given cache.
198
- #
199
- def warn_cache_small what
200
- warn "Warning: #{what} cache for #{identifier} smaller than 16 bytes."
201
- end
202
- # Raises an appropriate error message for the given cache.
203
- #
204
- def raise_cache_missing what
205
- raise "Error: The #{what} cache for #{identifier} is missing."
206
- end
207
-
208
- # Warns the user if the similarity index is small.
209
- #
210
- def warn_if_similarity_small
211
- warn_cache_small :similarity if backend_similarity.respond_to?(:cache_small?) && backend_similarity.cache_small?
212
- end
213
- # Alerts the user if the similarity index is not there.
214
- #
215
- def raise_unless_similarity_ok
216
- raise_cache_missing :similarity if backend_similarity.respond_to?(:cache_ok?) && !backend_similarity.cache_ok?
217
- end
218
-
219
- # Warns the user if the core or weights indexes are small.
220
- #
221
- def warn_if_index_small
222
- warn_cache_small :inverted if backend_inverted.respond_to?(:cache_small?) && backend_inverted.cache_small?
223
- warn_cache_small :weights if backend_weights.respond_to?(:cache_small?) && backend_weights.cache_small?
224
- end
225
- # Alerts the user if the core or weights indexes are not there.
226
- #
227
- def raise_unless_index_ok
228
- raise_cache_missing :inverted if backend_inverted.respond_to?(:cache_ok?) && !backend_inverted.cache_ok?
229
- raise_cache_missing :weights if backend_weights.respond_to?(:cache_ok?) && !backend_weights.cache_ok?
230
- end
231
-
232
160
  def to_s
233
161
  "#{self.class}(#{identifier})"
234
162
  end
@@ -42,7 +42,7 @@ module Picky
42
42
  #
43
43
  ids = if str_or_syms.include? str_or_sym
44
44
  ids = @inverted[str_or_sym]
45
- ids.delete id
45
+ ids.delete id
46
46
  ids.send where, id
47
47
  else
48
48
  str_or_syms << str_or_sym
@@ -15,6 +15,7 @@ module Picky
15
15
  :empty,
16
16
  :index,
17
17
  :reindex,
18
+ :reset_backend,
18
19
  :to => :categories
19
20
 
20
21
  # A list of indexed categories.
@@ -2,7 +2,7 @@ module Picky
2
2
 
3
3
  class Categories
4
4
 
5
- each_delegate :load_from_cache,
5
+ each_delegate :load,
6
6
  :analyze,
7
7
  :to => :categories
8
8
 
@@ -3,10 +3,8 @@ module Picky
3
3
  class Categories
4
4
 
5
5
  each_delegate :cache,
6
- :check,
7
6
  :clear,
8
- :backup,
9
- :restore,
7
+ :prepare,
10
8
  :to => :categories
11
9
 
12
10
  end
@@ -35,6 +35,7 @@ module Picky
35
35
  @key_format = options[:key_format]
36
36
  # @symbols = options[:use_symbols] || index.use_symbols? # TODO Symbols.
37
37
  @qualifiers = extract_qualifiers_from options
38
+ # TODO backend option!
38
39
 
39
40
  weights = options[:weights] || Generators::Weights::Default
40
41
  partial = options[:partial] || Generators::Partial::Default
@@ -53,19 +54,32 @@ module Picky
53
54
  @prepared = Backends::Memory::Text.new prepared_index_path
54
55
  end
55
56
 
56
- # Indexes and reloads the category.
57
+ # Indexes and loads the category.
57
58
  #
58
59
  def reindex
59
60
  index
60
- reload
61
+ load
61
62
  end
62
63
 
64
+ # Dumps both bundles.
65
+ #
63
66
  def dump
64
67
  exact.dump
65
68
  partial.dump
66
69
  timed_exclaim %Q{"#{identifier}": Generated -> #{index_directory.gsub("#{PICKY_ROOT}/", '')}.}
67
70
  end
68
71
 
72
+ # Resets backends in both bundles.
73
+ #
74
+ # This will only set the backend
75
+ #
76
+ def reset_backend backend
77
+ unless @backend
78
+ exact.reset_backend backend
79
+ partial.reset_backend backend
80
+ end
81
+ end
82
+
69
83
  # Index name.
70
84
  #
71
85
  def index_name