picky 2.0.0.pre2 → 2.0.0.pre3

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 (52) hide show
  1. data/lib/picky/application.rb +1 -1
  2. data/lib/picky/cli.rb +2 -2
  3. data/lib/picky/index/base.rb +1 -1
  4. data/lib/picky/internals/generators/similarity/double_metaphone.rb +32 -0
  5. data/lib/picky/internals/generators/similarity/metaphone.rb +32 -0
  6. data/lib/picky/internals/generators/similarity/{double_levenshtone.rb → phonetic.rb} +9 -21
  7. data/lib/picky/internals/generators/similarity/soundex.rb +32 -0
  8. data/lib/picky/internals/index/redis/basic.rb +15 -15
  9. data/lib/picky/internals/index/redis/list_hash.rb +13 -13
  10. data/lib/picky/internals/index/redis/string_hash.rb +11 -9
  11. data/lib/picky/internals/indexers/serial.rb +8 -8
  12. data/lib/picky/internals/indexing/bundle/base.rb +1 -1
  13. data/lib/picky/internals/indexing/bundle/memory.rb +1 -4
  14. data/lib/picky/internals/indexing/category.rb +3 -3
  15. data/lib/picky/internals/query/combinations/base.rb +5 -11
  16. data/lib/picky/internals/query/combinations/redis.rb +44 -24
  17. data/lib/picky/internals/query/indexes.rb +29 -24
  18. data/lib/picky/internals/query/token.rb +12 -12
  19. data/lib/picky/internals/tokenizers/base.rb +1 -1
  20. data/lib/picky/loader.rb +4 -4
  21. data/lib/picky/sources/couch.rb +4 -6
  22. data/lib/picky/sources/delicious.rb +1 -1
  23. data/spec/lib/analyzer_spec.rb +18 -0
  24. data/spec/lib/application_spec.rb +13 -3
  25. data/spec/lib/bundling_spec.rb +21 -0
  26. data/spec/lib/character_substituters/west_european_spec.rb +8 -2
  27. data/spec/lib/cli_spec.rb +45 -17
  28. data/spec/lib/index/redis_spec.rb +15 -0
  29. data/spec/lib/internals/adapters/rack/live_parameters_spec.rb +11 -6
  30. data/spec/lib/internals/frontend_adapters/rack_spec.rb +22 -0
  31. data/spec/lib/internals/generators/similarity/{double_levenshtone_spec.rb → double_metaphone_spec.rb} +1 -7
  32. data/spec/lib/internals/generators/similarity/metaphone_spec.rb +60 -0
  33. data/spec/lib/internals/generators/similarity/phonetic_spec.rb +13 -0
  34. data/spec/lib/internals/generators/similarity/soundex_spec.rb +60 -0
  35. data/spec/lib/internals/generators/similarity_generator_spec.rb +1 -1
  36. data/spec/lib/internals/index/file/basic_spec.rb +15 -5
  37. data/spec/lib/internals/index/redis/list_hash_spec.rb +34 -0
  38. data/spec/lib/internals/index/redis/string_hash_spec.rb +12 -0
  39. data/spec/lib/internals/indexed/bundle/memory_spec.rb +66 -0
  40. data/spec/lib/internals/indexing/bundle/memory_spec.rb +87 -71
  41. data/spec/lib/internals/indexing/bundle/redis_spec.rb +282 -0
  42. data/spec/lib/internals/indexing/bundle/super_base_spec.rb +1 -1
  43. data/spec/lib/internals/indexing/categories_spec.rb +49 -0
  44. data/spec/lib/internals/indexing/category_spec.rb +68 -35
  45. data/spec/lib/query/combinations/base_spec.rb +0 -9
  46. data/spec/lib/query/combinations/memory_spec.rb +0 -9
  47. data/spec/lib/query/combinations/redis_spec.rb +40 -5
  48. data/spec/lib/sources/couch_spec.rb +22 -0
  49. data/spec/lib/sources/csv_spec.rb +7 -0
  50. data/spec/lib/sources/db_spec.rb +7 -1
  51. data/spec/lib/sources/delicious_spec.rb +6 -2
  52. metadata +26 -5
@@ -2,13 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe Internals::Index::File::Basic do
4
4
 
5
- before(:each) do
6
- @file = described_class.new "some/cache/path/to/file"
5
+ let(:file) { described_class.new 'some/cache/path/to/file' }
6
+
7
+ describe 'backup_file_path_of' do
8
+ it 'returns a backup path relative to the path' do
9
+ file.backup_file_path_of('some/path/to/some.index').should == 'some/path/to/backup/some.index'
10
+ end
11
+ end
12
+
13
+ describe 'to_s' do
14
+ it 'returns the cache path with the default file extension' do
15
+ file.to_s.should == 'some/cache/path/to/file.index'
16
+ end
7
17
  end
8
18
 
9
- describe "backup_file_path_of" do
10
- it "returns a backup path relative to the path" do
11
- @file.backup_file_path_of('some/path/to/some.index').should == 'some/path/to/backup/some.index'
19
+ describe 'backup_directory' do
20
+ it "returns the cache path's backup path" do
21
+ file.backup_directory.should == 'some/cache/path/to/backup'
12
22
  end
13
23
  end
14
24
 
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Index::Redis::ListHash do
4
+
5
+ let(:index) { described_class.new :some_namespace }
6
+
7
+ describe 'member' do
8
+ it 'raises an error' do
9
+ expect {
10
+ index.member :some_sym
11
+ }.to raise_error("Can't retrieve a single value from a Redis ListHash. Use Index::Redis::StringHash.")
12
+ end
13
+ end
14
+
15
+ describe 'collection' do
16
+ it 'returns whatever comes back from the backend' do
17
+ backend = stub :backend
18
+ index.should_receive(:backend).and_return backend
19
+
20
+ backend.stub! :lrange => :some_lrange_result
21
+
22
+ index.collection(:anything).should == :some_lrange_result
23
+ end
24
+ it 'calls the right method on the backend' do
25
+ backend = stub :backend
26
+ index.should_receive(:backend).and_return backend
27
+
28
+ backend.should_receive(:lrange).once.with "some_namespace:some_sym", 0, -1
29
+
30
+ index.collection :some_sym
31
+ end
32
+ end
33
+
34
+ end
@@ -4,11 +4,23 @@ describe Internals::Index::Redis::StringHash do
4
4
 
5
5
  let(:index) { described_class.new :some_namespace }
6
6
 
7
+ describe 'dump' do
8
+ let(:backend) { index.backend }
9
+ it 'dumps correctly' do
10
+ backend.should_receive(:hset).once.ordered.with :some_namespace, :a, 1
11
+ backend.should_receive(:hset).once.ordered.with :some_namespace, :b, 2
12
+ backend.should_receive(:hset).once.ordered.with :some_namespace, :c, 3
13
+
14
+ index.dump a: 1, b: 2, c: 3
15
+ end
16
+ end
17
+
7
18
  describe 'collection' do
8
19
  it 'raises' do
9
20
  expect { index.collection :anything }.to raise_error("Can't retrieve a collection from a StringHash. Use Index::Redis::ListHash.")
10
21
  end
11
22
  end
23
+
12
24
  describe 'member' do
13
25
  before(:each) do
14
26
  @backend = stub :backend
@@ -10,6 +10,72 @@ describe Internals::Indexed::Bundle::Memory do
10
10
  @similarity = stub :similarity
11
11
  @bundle = described_class.new :some_name, @configuration, @similarity
12
12
  end
13
+
14
+ describe 'to_s' do
15
+ it 'does something' do
16
+ @bundle.to_s.should == <<-TO_S
17
+ Memory
18
+ Files:
19
+ Index: spec/test_directory/index/test/some_index/some_category_some_name_index.json
20
+ Weights: spec/test_directory/index/test/some_index/some_category_some_name_weights.json
21
+ Similarity: spec/test_directory/index/test/some_index/some_category_some_name_similarity.dump
22
+ Config: spec/test_directory/index/test/some_index/some_category_some_name_configuration.json
23
+ TO_S
24
+ end
25
+ end
26
+
27
+ describe 'clear_index' do
28
+ before(:each) do
29
+ @bundle.instance_variable_set(:@index, :not_empty)
30
+ end
31
+ it 'has not cleared the index' do
32
+ @bundle.index.should == :not_empty
33
+ end
34
+ it 'clears the index' do
35
+ @bundle.clear_index
36
+
37
+ @bundle.index.should be_empty
38
+ end
39
+ end
40
+ describe 'clear_weights' do
41
+ before(:each) do
42
+ @bundle.instance_variable_set(:@weights, :not_empty)
43
+ end
44
+ it 'has not cleared the weights' do
45
+ @bundle.weights.should == :not_empty
46
+ end
47
+ it 'clears the weights' do
48
+ @bundle.clear_weights
49
+
50
+ @bundle.weights.should be_empty
51
+ end
52
+ end
53
+ describe 'clear_similarity' do
54
+ before(:each) do
55
+ @bundle.instance_variable_set(:@similarity, :not_empty)
56
+ end
57
+ it 'has not cleared the similarity index' do
58
+ @bundle.similarity.should == :not_empty
59
+ end
60
+ it 'clears the similarity index' do
61
+ @bundle.clear_similarity
62
+
63
+ @bundle.similarity.should be_empty
64
+ end
65
+ end
66
+ describe 'clear_configuration' do
67
+ before(:each) do
68
+ @bundle.instance_variable_set(:@configuration, :not_empty)
69
+ end
70
+ it 'has not cleared the similarity index' do
71
+ @bundle.configuration.should == :not_empty
72
+ end
73
+ it 'clears the similarity index' do
74
+ @bundle.clear_configuration
75
+
76
+ @bundle.configuration.should be_empty
77
+ end
78
+ end
13
79
 
14
80
  describe 'identifier' do
15
81
  it 'should return a specific identifier' do
@@ -10,34 +10,50 @@ describe Internals::Indexing::Bundle::Memory do
10
10
  @partial = stub :partial
11
11
  @weights = stub :weights
12
12
  @similarity = stub :similarity
13
- @index = described_class.new :some_name, @configuration, @similarity, @partial, @weights
14
13
  end
15
-
14
+ let(:index) { described_class.new :some_name, @configuration, @similarity, @partial, @weights }
15
+
16
+ describe 'raise_cache_missing' do
17
+ it 'does something' do
18
+ expect {
19
+ index.raise_cache_missing :similarity
20
+ }.to raise_error("Error: The similarity cache for some_index:some_category:some_name is missing.")
21
+ end
22
+ end
23
+
24
+ describe 'warn_cache_small' do
25
+ it 'warns the user' do
26
+ index.should_receive(:warn).once.with "Warning: similarity cache for some_index:some_category:some_name smaller than 16 bytes."
27
+
28
+ index.warn_cache_small :similarity
29
+ end
30
+ end
31
+
16
32
  describe 'identifier' do
17
33
  it 'should return a specific identifier' do
18
- @index.identifier.should == 'some_index:some_category:some_name'
34
+ index.identifier.should == 'some_index:some_category:some_name'
19
35
  end
20
36
  end
21
37
 
22
38
  describe 'initialize_index_for' do
23
39
  context 'token not yet assigned' do
24
40
  before(:each) do
25
- @index.stub! :index => {}
41
+ index.stub! :index => {}
26
42
  end
27
43
  it 'should assign it an empty array' do
28
- @index.initialize_index_for :some_token
44
+ index.initialize_index_for :some_token
29
45
 
30
- @index.index[:some_token].should == []
46
+ index.index[:some_token].should == []
31
47
  end
32
48
  end
33
49
  context 'token already assigned' do
34
50
  before(:each) do
35
- @index.stub! :index => { :some_token => :already_assigned }
51
+ index.stub! :index => { :some_token => :already_assigned }
36
52
  end
37
53
  it 'should not assign it anymore' do
38
- @index.initialize_index_for :some_token
54
+ index.initialize_index_for :some_token
39
55
 
40
- @index.index[:some_token].should == :already_assigned
56
+ index.index[:some_token].should == :already_assigned
41
57
  end
42
58
  end
43
59
  end
@@ -46,123 +62,123 @@ describe Internals::Indexing::Bundle::Memory do
46
62
  before(:each) do
47
63
  files = stub :files
48
64
  files.should_receive(:retrieve).once.and_yield ' 1234', :some_token
49
- @index.stub! :files => files
65
+ index.stub! :files => files
50
66
 
51
67
  @ary = stub :ary
52
68
  @internal_index.should_receive(:[]).any_number_of_times.and_return @ary
53
- @index.stub! :index => @internal_index
69
+ index.stub! :index => @internal_index
54
70
  end
55
71
  context 'id key format' do
56
72
  before(:each) do
57
- @index.should_receive(:[]).once.with(:key_format).and_return :to_i
73
+ index.should_receive(:[]).once.with(:key_format).and_return :to_i
58
74
  end
59
75
  it 'should call the other methods correctly' do
60
76
  @ary.should_receive(:<<).once.with 1234
61
77
 
62
- @index.retrieve
78
+ index.retrieve
63
79
  end
64
80
  end
65
81
  context 'other key format' do
66
82
  before(:each) do
67
- @index.should_receive(:[]).once.with(:key_format).and_return :strip
83
+ index.should_receive(:[]).once.with(:key_format).and_return :strip
68
84
  end
69
85
  it 'should call the other methods correctly' do
70
86
  @ary.should_receive(:<<).once.with '1234'
71
87
 
72
- @index.retrieve
88
+ index.retrieve
73
89
  end
74
90
  end
75
91
  context 'no key format - default' do
76
92
  before(:each) do
77
- @index.should_receive(:[]).once.with(:key_format).and_return nil
93
+ index.should_receive(:[]).once.with(:key_format).and_return nil
78
94
  end
79
95
  it 'should call the other methods correctly' do
80
96
  @ary.should_receive(:<<).once.with 1234
81
97
 
82
- @index.retrieve
98
+ index.retrieve
83
99
  end
84
100
  end
85
101
  end
86
102
 
87
103
  describe 'load_from_index_file' do
88
104
  it 'should call two methods in order' do
89
- @index.should_receive(:load_from_index_generation_message).once.ordered
90
- @index.should_receive(:clear).once.ordered
91
- @index.should_receive(:retrieve).once.ordered
105
+ index.should_receive(:load_from_index_generation_message).once.ordered
106
+ index.should_receive(:clear).once.ordered
107
+ index.should_receive(:retrieve).once.ordered
92
108
 
93
- @index.load_from_index_file
109
+ index.load_from_index_file
94
110
  end
95
111
  end
96
112
 
97
113
  describe 'generate_derived' do
98
114
  it 'should call two methods in order' do
99
- @index.should_receive(:generate_weights).once.ordered
100
- @index.should_receive(:generate_similarity).once.ordered
115
+ index.should_receive(:generate_weights).once.ordered
116
+ index.should_receive(:generate_similarity).once.ordered
101
117
 
102
- @index.generate_derived
118
+ index.generate_derived
103
119
  end
104
120
  end
105
121
 
106
122
  describe 'generate_caches_from_memory' do
107
123
  it 'should call two methods in order' do
108
- @index.should_receive(:cache_from_memory_generation_message).once.ordered
109
- @index.should_receive(:generate_derived).once.ordered
124
+ index.should_receive(:cache_from_memory_generation_message).once.ordered
125
+ index.should_receive(:generate_derived).once.ordered
110
126
 
111
- @index.generate_caches_from_memory
127
+ index.generate_caches_from_memory
112
128
  end
113
129
  end
114
130
 
115
131
  describe 'generate_caches_from_source' do
116
132
  it 'should call two methods in order' do
117
- @index.should_receive(:load_from_index_file).once.ordered
118
- @index.should_receive(:generate_caches_from_memory).once.ordered
133
+ index.should_receive(:load_from_index_file).once.ordered
134
+ index.should_receive(:generate_caches_from_memory).once.ordered
119
135
 
120
- @index.generate_caches_from_source
136
+ index.generate_caches_from_source
121
137
  end
122
138
  end
123
139
 
124
140
  describe 'dump' do
125
141
  it 'should trigger dumps' do
126
- @index.should_receive(:dump_index).once.with
127
- @index.should_receive(:dump_weights).once.with
128
- @index.should_receive(:dump_similarity).once.with
129
- @index.should_receive(:dump_configuration).once.with
142
+ index.should_receive(:dump_index).once.with
143
+ index.should_receive(:dump_weights).once.with
144
+ index.should_receive(:dump_similarity).once.with
145
+ index.should_receive(:dump_configuration).once.with
130
146
 
131
- @index.dump
147
+ index.dump
132
148
  end
133
149
  end
134
150
 
135
151
  describe 'raise_unless_cache_exists' do
136
152
  it "calls methods in order" do
137
- @index.should_receive(:raise_unless_index_exists).once.ordered
138
- @index.should_receive(:raise_unless_similarity_exists).once.ordered
153
+ index.should_receive(:raise_unless_index_exists).once.ordered
154
+ index.should_receive(:raise_unless_similarity_exists).once.ordered
139
155
 
140
- @index.raise_unless_cache_exists
156
+ index.raise_unless_cache_exists
141
157
  end
142
158
  end
143
159
  describe 'raise_unless_index_exists' do
144
160
  context 'partial strategy saved' do
145
161
  before(:each) do
146
162
  strategy = stub :strategy, :saved? => true
147
- @index.stub! :partial_strategy => strategy
163
+ index.stub! :partial_strategy => strategy
148
164
  end
149
165
  it "calls the methods in order" do
150
- @index.should_receive(:warn_if_index_small).once.ordered
151
- @index.should_receive(:raise_unless_index_ok).once.ordered
166
+ index.should_receive(:warn_if_index_small).once.ordered
167
+ index.should_receive(:raise_unless_index_ok).once.ordered
152
168
 
153
- @index.raise_unless_index_exists
169
+ index.raise_unless_index_exists
154
170
  end
155
171
  end
156
172
  context 'partial strategy not saved' do
157
173
  before(:each) do
158
174
  strategy = stub :strategy, :saved? => false
159
- @index.stub! :partial_strategy => strategy
175
+ index.stub! :partial_strategy => strategy
160
176
  end
161
177
  it "calls nothing" do
162
- @index.should_receive(:warn_if_index_small).never
163
- @index.should_receive(:raise_unless_index_ok).never
178
+ index.should_receive(:warn_if_index_small).never
179
+ index.should_receive(:raise_unless_index_ok).never
164
180
 
165
- @index.raise_unless_index_exists
181
+ index.raise_unless_index_exists
166
182
  end
167
183
  end
168
184
  end
@@ -170,40 +186,40 @@ describe Internals::Indexing::Bundle::Memory do
170
186
  context 'similarity strategy saved' do
171
187
  before(:each) do
172
188
  strategy = stub :strategy, :saved? => true
173
- @index.stub! :similarity_strategy => strategy
189
+ index.stub! :similarity_strategy => strategy
174
190
  end
175
191
  it "calls the methods in order" do
176
- @index.should_receive(:warn_if_similarity_small).once.ordered
177
- @index.should_receive(:raise_unless_similarity_ok).once.ordered
192
+ index.should_receive(:warn_if_similarity_small).once.ordered
193
+ index.should_receive(:raise_unless_similarity_ok).once.ordered
178
194
 
179
- @index.raise_unless_similarity_exists
195
+ index.raise_unless_similarity_exists
180
196
  end
181
197
  end
182
198
  context 'similarity strategy not saved' do
183
199
  before(:each) do
184
200
  strategy = stub :strategy, :saved? => false
185
- @index.stub! :similarity_strategy => strategy
201
+ index.stub! :similarity_strategy => strategy
186
202
  end
187
203
  it "calls nothing" do
188
- @index.should_receive(:warn_if_similarity_small).never
189
- @index.should_receive(:raise_unless_similarity_ok).never
204
+ index.should_receive(:warn_if_similarity_small).never
205
+ index.should_receive(:raise_unless_similarity_ok).never
190
206
 
191
- @index.raise_unless_similarity_exists
207
+ index.raise_unless_similarity_exists
192
208
  end
193
209
  end
194
210
  end
195
211
  describe 'warn_if_similarity_small' do
196
212
  before(:each) do
197
- @files = @index.files
213
+ @files = index.files
198
214
  end
199
215
  context "files similarity cache small" do
200
216
  before(:each) do
201
217
  @files.stub! :similarity_cache_small? => true
202
218
  end
203
219
  it "warns" do
204
- @index.should_receive(:warn_cache_small).once.with :similarity
220
+ index.should_receive(:warn_cache_small).once.with :similarity
205
221
 
206
- @index.warn_if_similarity_small
222
+ index.warn_if_similarity_small
207
223
  end
208
224
  end
209
225
  context "files similarity cache not small" do
@@ -211,24 +227,24 @@ describe Internals::Indexing::Bundle::Memory do
211
227
  @files.stub! :similarity_cache_small? => false
212
228
  end
213
229
  it "does not warn" do
214
- @index.should_receive(:warn_cache_small).never
230
+ index.should_receive(:warn_cache_small).never
215
231
 
216
- @index.warn_if_similarity_small
232
+ index.warn_if_similarity_small
217
233
  end
218
234
  end
219
235
  end
220
236
  describe 'raise_unless_similarity_ok' do
221
237
  before(:each) do
222
- @files = @index.files
238
+ @files = index.files
223
239
  end
224
240
  context "files similarity cache ok" do
225
241
  before(:each) do
226
242
  @files.stub! :similarity_cache_ok? => true
227
243
  end
228
244
  it "warns" do
229
- @index.should_receive(:raise_cache_missing).never
245
+ index.should_receive(:raise_cache_missing).never
230
246
 
231
- @index.raise_unless_similarity_ok
247
+ index.raise_unless_similarity_ok
232
248
  end
233
249
  end
234
250
  context "files similarity cache not ok" do
@@ -236,34 +252,34 @@ describe Internals::Indexing::Bundle::Memory do
236
252
  @files.stub! :similarity_cache_ok? => false
237
253
  end
238
254
  it "does not warn" do
239
- @index.should_receive(:raise_cache_missing).once.with :similarity
255
+ index.should_receive(:raise_cache_missing).once.with :similarity
240
256
 
241
- @index.raise_unless_similarity_ok
257
+ index.raise_unless_similarity_ok
242
258
  end
243
259
  end
244
260
  end
245
261
 
246
262
  describe 'initialization' do
247
263
  it 'should initialize the index correctly' do
248
- @index.index.should == {}
264
+ index.index.should == {}
249
265
  end
250
266
  it 'should initialize the weights index correctly' do
251
- @index.weights.should == {}
267
+ index.weights.should == {}
252
268
  end
253
269
  it 'should initialize the similarity index correctly' do
254
- @index.similarity.should == {}
270
+ index.similarity.should == {}
255
271
  end
256
272
  it 'should initialize the configuration correctly' do
257
- @index.configuration.should == {}
273
+ index.configuration.should == {}
258
274
  end
259
275
  it 'should initialize the partial strategy correctly' do
260
- @index.partial_strategy.should == @partial
276
+ index.partial_strategy.should == @partial
261
277
  end
262
278
  it 'should initialize the weights strategy correctly' do
263
- @index.weights_strategy.should == @weights
279
+ index.weights_strategy.should == @weights
264
280
  end
265
281
  it 'should initialize the similarity strategy correctly' do
266
- @index.similarity_strategy.should == @similarity
282
+ index.similarity_strategy.should == @similarity
267
283
  end
268
284
  end
269
285