picky 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/lib/picky/application.rb +12 -12
  2. data/lib/picky/backends/backend.rb +17 -0
  3. data/lib/picky/{backend → backends}/file/basic.rb +1 -1
  4. data/lib/picky/{backend → backends}/file/json.rb +1 -1
  5. data/lib/picky/{backend → backends}/file/marshal.rb +1 -1
  6. data/lib/picky/{backend → backends}/file/text.rb +1 -1
  7. data/lib/picky/backends/memory.rb +53 -0
  8. data/lib/picky/{backend → backends}/redis/basic.rb +9 -14
  9. data/lib/picky/backends/redis/float_hash.rb +26 -0
  10. data/lib/picky/{backend → backends}/redis/list_hash.rb +7 -11
  11. data/lib/picky/{backend → backends}/redis/string_hash.rb +7 -11
  12. data/lib/picky/backends/redis.rb +87 -0
  13. data/lib/picky/bundle.rb +107 -11
  14. data/lib/picky/category.rb +5 -5
  15. data/lib/picky/index.rb +329 -0
  16. data/lib/picky/index_indexed.rb +31 -0
  17. data/lib/picky/index_indexing.rb +161 -0
  18. data/lib/picky/indexed/bundle.rb +112 -0
  19. data/lib/picky/indexed/wrappers/exact_first.rb +1 -1
  20. data/lib/picky/indexers/parallel.rb +2 -1
  21. data/lib/picky/indexers/serial.rb +2 -1
  22. data/lib/picky/indexes_indexing.rb +1 -1
  23. data/lib/picky/indexing/bundle.rb +188 -0
  24. data/lib/picky/indexing/wrappers/category/location.rb +1 -1
  25. data/lib/picky/interfaces/live_parameters.rb +8 -8
  26. data/lib/picky/loader.rb +24 -38
  27. data/lib/picky/migrations/from_30_to_31.rb +61 -0
  28. data/lib/picky/query/allocation.rb +10 -5
  29. data/lib/picky/query/combinations.rb +70 -0
  30. data/lib/picky/query/indexes.rb +8 -7
  31. data/lib/picky/query/indexes_check.rb +47 -0
  32. data/lib/picky/query/token.rb +16 -29
  33. data/lib/picky/query/tokens.rb +4 -20
  34. data/lib/picky/search.rb +51 -58
  35. data/lib/picky/tokenizer.rb +231 -0
  36. data/lib/picky/tokenizers/location.rb +1 -1
  37. data/lib/tasks/try.rake +4 -12
  38. data/lib/tasks/try.rb +37 -0
  39. data/spec/lib/application_spec.rb +5 -5
  40. data/spec/lib/{backend → backends}/file/basic_spec.rb +2 -2
  41. data/spec/lib/{backend → backends}/file/json_spec.rb +2 -2
  42. data/spec/lib/{backend → backends}/file/marshal_spec.rb +2 -2
  43. data/spec/lib/{backend → backends}/file/text_spec.rb +1 -1
  44. data/spec/lib/backends/memory_spec.rb +77 -0
  45. data/spec/lib/{backend → backends}/redis/basic_spec.rb +19 -21
  46. data/spec/lib/backends/redis/float_hash_spec.rb +38 -0
  47. data/spec/lib/backends/redis/list_hash_spec.rb +27 -0
  48. data/spec/lib/backends/redis/string_hash_spec.rb +38 -0
  49. data/spec/lib/backends/redis_spec.rb +79 -0
  50. data/spec/lib/categories_indexed_spec.rb +3 -3
  51. data/spec/lib/category_indexed_spec.rb +6 -6
  52. data/spec/lib/category_indexing_spec.rb +1 -1
  53. data/spec/lib/category_spec.rb +1 -1
  54. data/spec/lib/frontend_adapters/rack_spec.rb +2 -2
  55. data/spec/lib/{indexes/index_indexed_spec.rb → index_indexed_spec.rb} +1 -1
  56. data/spec/lib/{indexes/index_indexing_spec.rb → index_indexing_spec.rb} +1 -1
  57. data/spec/lib/{indexes/index_spec.rb → index_spec.rb} +1 -1
  58. data/spec/lib/indexed/{bundle/memory_spec.rb → memory_spec.rb} +18 -18
  59. data/spec/lib/indexed/wrappers/exact_first_spec.rb +2 -2
  60. data/spec/lib/indexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +3 -3
  61. data/spec/lib/indexing/bundle_spec.rb +302 -0
  62. data/spec/lib/query/allocation_spec.rb +21 -11
  63. data/spec/lib/query/combination_spec.rb +2 -2
  64. data/spec/lib/query/{combinations/base_spec.rb → combinations_spec.rb} +1 -1
  65. data/spec/lib/query/indexes_check_spec.rb +25 -0
  66. data/spec/lib/query/indexes_spec.rb +5 -1
  67. data/spec/lib/query/token_spec.rb +18 -20
  68. data/spec/lib/query/tokens_spec.rb +14 -65
  69. data/spec/lib/search_spec.rb +36 -37
  70. data/spec/lib/tasks/try_spec.rb +51 -0
  71. data/spec/lib/{tokenizers/base_spec.rb → tokenizer_spec.rb} +15 -44
  72. metadata +64 -81
  73. data/lib/picky/backend/base.rb +0 -121
  74. data/lib/picky/backend/files.rb +0 -28
  75. data/lib/picky/backend/redis.rb +0 -44
  76. data/lib/picky/indexed/bundle/base.rb +0 -47
  77. data/lib/picky/indexed/bundle/memory.rb +0 -88
  78. data/lib/picky/indexed/bundle/redis.rb +0 -91
  79. data/lib/picky/indexes/index.rb +0 -328
  80. data/lib/picky/indexes/index_indexed.rb +0 -35
  81. data/lib/picky/indexes/index_indexing.rb +0 -165
  82. data/lib/picky/indexes/memory.rb +0 -20
  83. data/lib/picky/indexes/redis.rb +0 -20
  84. data/lib/picky/indexing/bundle/base.rb +0 -242
  85. data/lib/picky/indexing/bundle/memory.rb +0 -26
  86. data/lib/picky/indexing/bundle/redis.rb +0 -26
  87. data/lib/picky/query/combinations/base.rb +0 -74
  88. data/lib/picky/query/combinations/memory.rb +0 -52
  89. data/lib/picky/query/combinations/redis.rb +0 -90
  90. data/lib/picky/query.rb +0 -6
  91. data/lib/picky/tokenizers/base.rb +0 -231
  92. data/lib/picky/tokenizers/index.rb +0 -34
  93. data/lib/picky/tokenizers/query.rb +0 -61
  94. data/spec/lib/backend/files_spec.rb +0 -189
  95. data/spec/lib/backend/redis/list_hash_spec.rb +0 -40
  96. data/spec/lib/backend/redis/string_hash_spec.rb +0 -47
  97. data/spec/lib/backend/redis_spec.rb +0 -170
  98. data/spec/lib/indexed/bundle/redis_spec.rb +0 -41
  99. data/spec/lib/indexes/redis_spec.rb +0 -15
  100. data/spec/lib/indexing/bundle/base_spec.rb +0 -38
  101. data/spec/lib/indexing/bundle/memory_spec.rb +0 -287
  102. data/spec/lib/indexing/bundle/redis_spec.rb +0 -283
  103. data/spec/lib/query/combinations/memory_spec.rb +0 -158
  104. data/spec/lib/query/combinations/redis_spec.rb +0 -172
  105. data/spec/lib/tokenizers/index_spec.rb +0 -69
  106. data/spec/lib/tokenizers/query_spec.rb +0 -121
@@ -0,0 +1,302 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Indexing::Bundle do
4
+
5
+ before(:each) do
6
+ @index = Picky::Index.new :some_index
7
+ @category = Picky::Category.new :some_category, @index
8
+ @similarity = Picky::Similarity::DoubleMetaphone.new 3
9
+ end
10
+ let(:bundle) { described_class.new :some_name, @category, Picky::Backends::Memory.new, :some_weights, :some_partial, @similarity }
11
+
12
+ describe 'identifier' do
13
+ it 'is correct' do
14
+ bundle.identifier.should == 'test:some_index:some_category:some_name'
15
+ end
16
+ end
17
+
18
+ describe 'similar' do
19
+ before(:each) do
20
+ bundle.similarity = @similarity.generate_from( :dragon => [1,2,3], :dargon => [4,5,6] )
21
+ end
22
+ it 'returns the right similars (not itself)' do
23
+ bundle.similar(:dragon).should == [:dargon]
24
+ end
25
+ it 'returns the right similars' do
26
+ bundle.similar(:trkn).should == [:dragon, :dargon]
27
+ end
28
+ it 'performs' do
29
+ performance_of { bundle.similar(:dragon) }.should < 0.000075
30
+ end
31
+ it 'performs' do
32
+ performance_of { bundle.similar(:trkn) }.should < 0.00006
33
+ end
34
+ end
35
+
36
+ describe 'raise_cache_missing' do
37
+ it 'does something' do
38
+ expect {
39
+ bundle.raise_cache_missing :similarity
40
+ }.to raise_error("Error: The similarity cache for test:some_index:some_category:some_name is missing.")
41
+ end
42
+ end
43
+
44
+ describe 'warn_cache_small' do
45
+ it 'warns the user' do
46
+ bundle.should_receive(:warn).once.with "Warning: similarity cache for test:some_index:some_category:some_name smaller than 16 bytes."
47
+
48
+ bundle.warn_cache_small :similarity
49
+ end
50
+ end
51
+
52
+ describe 'identifier' do
53
+ it 'should return a specific identifier' do
54
+ bundle.identifier.should == 'test:some_index:some_category:some_name'
55
+ end
56
+ end
57
+
58
+ describe 'initialize_index_for' do
59
+ context 'token not yet assigned' do
60
+ before(:each) do
61
+ bundle.stub! :index => {}
62
+ end
63
+ it 'should assign it an empty array' do
64
+ bundle.initialize_inverted_index_for :some_token
65
+
66
+ bundle.inverted[:some_token].should == []
67
+ end
68
+ end
69
+ context 'token already assigned' do
70
+ before(:each) do
71
+ bundle.stub! :index => { :some_token => :already_assigned }
72
+ end
73
+ it 'should not assign it anymore' do
74
+ bundle.initialize_inverted_index_for :some_token
75
+
76
+ bundle.index[:some_token].should == :already_assigned
77
+ end
78
+ end
79
+ end
80
+
81
+ describe 'retrieve' do
82
+ before(:each) do
83
+ prepared = stub :prepared
84
+ prepared.should_receive(:retrieve).once.and_yield ' 1234', :some_token
85
+ bundle.stub! :prepared => prepared
86
+
87
+ @ary = stub :ary
88
+ inverted = stub :inverted, :[] => @ary
89
+ bundle.stub! :inverted => inverted
90
+ end
91
+ context 'id key format' do
92
+ before(:each) do
93
+ @category.stub! :key_format => :to_i
94
+ end
95
+ it 'should call the other methods correctly' do
96
+ @ary.should_receive(:<<).once.with 1234
97
+
98
+ bundle.retrieve
99
+ end
100
+ end
101
+ context 'other key format' do
102
+ before(:each) do
103
+ @category.stub! :key_format => :strip
104
+ end
105
+ it 'should call the other methods correctly' do
106
+ @ary.should_receive(:<<).once.with '1234'
107
+
108
+ bundle.retrieve
109
+ end
110
+ end
111
+ context 'no key format - default' do
112
+ before(:each) do
113
+ @category.stub! :key_format => nil
114
+ end
115
+ it 'should call the other methods correctly' do
116
+ @ary.should_receive(:<<).once.with 1234
117
+
118
+ bundle.retrieve
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'load_from_index_file' do
124
+ it 'should call two methods in order' do
125
+ bundle.should_receive(:load_from_prepared_index_generation_message).once.ordered
126
+ bundle.should_receive(:clear).once.ordered
127
+ bundle.should_receive(:retrieve).once.ordered
128
+
129
+ bundle.load_from_prepared_index_file
130
+ end
131
+ end
132
+
133
+ describe 'generate_derived' do
134
+ it 'should call two methods in order' do
135
+ bundle.should_receive(:generate_weights).once.ordered
136
+ bundle.should_receive(:generate_similarity).once.ordered
137
+
138
+ bundle.generate_derived
139
+ end
140
+ end
141
+
142
+ describe 'generate_caches_from_memory' do
143
+ it 'should call two methods in order' do
144
+ bundle.should_receive(:cache_from_memory_generation_message).once.ordered
145
+ bundle.should_receive(:generate_derived).once.ordered
146
+
147
+ bundle.generate_caches_from_memory
148
+ end
149
+ end
150
+
151
+ describe 'generate_caches_from_source' do
152
+ it 'should call two methods in order' do
153
+ bundle.should_receive(:load_from_prepared_index_file).once.ordered
154
+ bundle.should_receive(:generate_caches_from_memory).once.ordered
155
+
156
+ bundle.generate_caches_from_source
157
+ end
158
+ end
159
+
160
+ describe 'dump' do
161
+ it 'should trigger dumps' do
162
+ bundle.stub! :timed_exclaim
163
+
164
+ bundle.should_receive(:dump_inverted).once.with
165
+ bundle.should_receive(:dump_weights).once.with
166
+ bundle.should_receive(:dump_similarity).once.with
167
+ bundle.should_receive(:dump_configuration).once.with
168
+
169
+ bundle.dump
170
+ end
171
+ end
172
+
173
+ describe 'raise_unless_cache_exists' do
174
+ it "calls methods in order" do
175
+ bundle.should_receive(:raise_unless_index_exists).once.ordered
176
+ bundle.should_receive(:raise_unless_similarity_exists).once.ordered
177
+
178
+ bundle.raise_unless_cache_exists
179
+ end
180
+ end
181
+ describe 'raise_unless_index_exists' do
182
+ context 'partial strategy saved' do
183
+ before(:each) do
184
+ strategy = stub :strategy, :saved? => true
185
+ bundle.stub! :partial_strategy => strategy
186
+ end
187
+ it "calls the methods in order" do
188
+ bundle.should_receive(:warn_if_index_small).once.ordered
189
+ bundle.should_receive(:raise_unless_index_ok).once.ordered
190
+
191
+ bundle.raise_unless_index_exists
192
+ end
193
+ end
194
+ context 'partial strategy not saved' do
195
+ before(:each) do
196
+ strategy = stub :strategy, :saved? => false
197
+ bundle.stub! :partial_strategy => strategy
198
+ end
199
+ it "calls nothing" do
200
+ bundle.should_receive(:warn_if_index_small).never
201
+ bundle.should_receive(:raise_unless_index_ok).never
202
+
203
+ bundle.raise_unless_index_exists
204
+ end
205
+ end
206
+ end
207
+ describe 'raise_unless_similarity_exists' do
208
+ context 'similarity strategy saved' do
209
+ before(:each) do
210
+ strategy = stub :strategy, :saved? => true
211
+ bundle.stub! :similarity_strategy => strategy
212
+ end
213
+ it "calls the methods in order" do
214
+ bundle.should_receive(:warn_if_similarity_small).once.ordered
215
+ bundle.should_receive(:raise_unless_similarity_ok).once.ordered
216
+
217
+ bundle.raise_unless_similarity_exists
218
+ end
219
+ end
220
+ context 'similarity strategy not saved' do
221
+ before(:each) do
222
+ strategy = stub :strategy, :saved? => false
223
+ bundle.stub! :similarity_strategy => strategy
224
+ end
225
+ it "calls nothing" do
226
+ bundle.should_receive(:warn_if_similarity_small).never
227
+ bundle.should_receive(:raise_unless_similarity_ok).never
228
+
229
+ bundle.raise_unless_similarity_exists
230
+ end
231
+ end
232
+ end
233
+ describe 'warn_if_similarity_small' do
234
+ context "files similarity cache small" do
235
+ before(:each) do
236
+ bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_small? => true)
237
+ end
238
+ it "warns" do
239
+ bundle.should_receive(:warn_cache_small).once.with :similarity
240
+
241
+ bundle.warn_if_similarity_small
242
+ end
243
+ end
244
+ context "files similarity cache not small" do
245
+ before(:each) do
246
+ bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_small? => false)
247
+ end
248
+ it "does not warn" do
249
+ bundle.should_receive(:warn_cache_small).never
250
+
251
+ bundle.warn_if_similarity_small
252
+ end
253
+ end
254
+ end
255
+ describe 'raise_unless_similarity_ok' do
256
+ context "files similarity cache ok" do
257
+ before(:each) do
258
+ bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_ok? => true)
259
+ end
260
+ it "warns" do
261
+ bundle.should_receive(:raise_cache_missing).never
262
+
263
+ bundle.raise_unless_similarity_ok
264
+ end
265
+ end
266
+ context "files similarity cache not ok" do
267
+ before(:each) do
268
+ bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_ok? => false)
269
+ end
270
+ it "does not warn" do
271
+ bundle.should_receive(:raise_cache_missing).once.with :similarity
272
+
273
+ bundle.raise_unless_similarity_ok
274
+ end
275
+ end
276
+ end
277
+
278
+ describe 'initialization' do
279
+ it 'should initialize the index correctly' do
280
+ bundle.inverted.should == {}
281
+ end
282
+ it 'should initialize the weights index correctly' do
283
+ bundle.weights.should == {}
284
+ end
285
+ it 'should initialize the similarity index correctly' do
286
+ bundle.similarity.should == {}
287
+ end
288
+ it 'should initialize the configuration correctly' do
289
+ bundle.configuration.should == {}
290
+ end
291
+ # it 'should initialize the partial strategy correctly' do
292
+ # bundle.partial_strategy.should == @partial
293
+ # end
294
+ # it 'should initialize the weights strategy correctly' do
295
+ # bundle.weights_strategy.should == @weights
296
+ # end
297
+ it 'should initialize the similarity strategy correctly' do
298
+ bundle.similarity_strategy.should == @similarity
299
+ end
300
+ end
301
+
302
+ end
@@ -3,8 +3,10 @@ require 'spec_helper'
3
3
  describe Picky::Query::Allocation do
4
4
 
5
5
  before(:each) do
6
+ @backend = stub :backend
7
+ @index = stub :index, :result_identifier => :some_result_identifier, :backend => @backend
6
8
  @combinations = stub :combinations
7
- @allocation = described_class.new @combinations, :some_result_identifier
9
+ @allocation = described_class.new @index, @combinations
8
10
  end
9
11
 
10
12
  describe "eql?" do
@@ -130,11 +132,13 @@ describe Picky::Query::Allocation do
130
132
  describe 'to_result' do
131
133
  context 'with few combinations' do
132
134
  before(:each) do
133
- @allocation = described_class.new stub(:combinations, :ids => [1,2,3], :to_result => [:some_result]), :some_result_identifier
135
+ @allocation = described_class.new @index, stub(:combinations, :to_result => [:some_result])
134
136
  @allocation.instance_variable_set :@score, :some_score
135
137
  end
136
138
  context 'with ids' do
137
139
  it 'should output an array of information' do
140
+ @backend.stub! :ids => [1,2,3]
141
+
138
142
  @allocation.process! 20, 0
139
143
 
140
144
  @allocation.to_result.should == [:some_result_identifier, :some_score, 3, [:some_result], [1, 2, 3]]
@@ -143,12 +147,14 @@ describe Picky::Query::Allocation do
143
147
  end
144
148
  context 'with results' do
145
149
  before(:each) do
146
- combinations = stub :combinations, :ids => [1,2,3], :to_result => [:some_result1, :some_result2]
147
- @allocation = described_class.new combinations, :some_result_identifier
150
+ combinations = stub :combinations, :to_result => [:some_result1, :some_result2]
151
+ @allocation = described_class.new @index, combinations
148
152
  @allocation.instance_variable_set :@score, :some_score
149
153
  end
150
154
  context 'with ids' do
151
155
  it 'should output an array of information' do
156
+ @backend.stub! :ids => [1,2,3]
157
+
152
158
  @allocation.process! 20, 0
153
159
 
154
160
  @allocation.to_result.should == [:some_result_identifier, :some_score, 3, [:some_result1, :some_result2], [1, 2, 3]]
@@ -157,10 +163,12 @@ describe Picky::Query::Allocation do
157
163
  end
158
164
  context 'without results' do
159
165
  before(:each) do
160
- @allocation = described_class.new stub(:combinations, :ids => [], :to_result => []), :some_result_identifier
166
+ @allocation = described_class.new @index, stub(:combinations, :to_result => [])
161
167
  @allocation.instance_variable_set :@score, :some_score
162
168
  end
163
169
  it 'should return nil' do
170
+ @backend.stub! :ids => []
171
+
164
172
  @allocation.process! 20, 0
165
173
 
166
174
  @allocation.to_result.should == nil
@@ -170,10 +178,12 @@ describe Picky::Query::Allocation do
170
178
 
171
179
  describe 'to_json' do
172
180
  before(:each) do
173
- @allocation = described_class.new stub(:combination, :ids => [1,2,3,4,5,6,7], :to_result => [:some_result1, :some_result2]), :some_result_identifier
181
+ @allocation = described_class.new @index, stub(:combination, :to_result => [:some_result1, :some_result2])
174
182
  @allocation.instance_variable_set :@score, :some_score
175
183
  end
176
184
  it 'should output the correct json string' do
185
+ @backend.stub! :ids => [1,2,3,4,5,6,7]
186
+
177
187
  @allocation.process! 20, 0
178
188
 
179
189
  @allocation.to_json.should == '["some_result_identifier","some_score",7,["some_result1","some_result2"],[1,2,3,4,5,6,7]]'
@@ -190,9 +200,9 @@ describe Picky::Query::Allocation do
190
200
 
191
201
  describe "<=>" do
192
202
  it "should sort higher first" do
193
- first = described_class.new [], :some_result_identifier
203
+ first = described_class.new @index, []
194
204
  first.instance_variable_set :@score, 20
195
- second = described_class.new [], :some_result_identifier
205
+ second = described_class.new @index, []
196
206
  second.instance_variable_set :@score, 10
197
207
 
198
208
  first.<=>(second).should == -1
@@ -201,11 +211,11 @@ describe Picky::Query::Allocation do
201
211
 
202
212
  describe "sort!" do
203
213
  it "should sort correctly" do
204
- first = described_class.new :whatever, :some_result_identifier
214
+ first = described_class.new @index, :whatever
205
215
  first.instance_variable_set :@score, 20
206
- second = described_class.new :whatever, :some_result_identifier
216
+ second = described_class.new @index, :whatever
207
217
  second.instance_variable_set :@score, 10
208
- third = described_class.new :whatever, :some_result_identifier
218
+ third = described_class.new @index, :whatever
209
219
  third.instance_variable_set :@score, 5
210
220
 
211
221
  allocations = [second, third, first]
@@ -6,7 +6,7 @@ describe Picky::Query::Combination do
6
6
 
7
7
  before(:each) do
8
8
  @bundle = stub :bundle, :identifier => :bundle_name
9
- @token = Picky::Query::Token.processed('some_text~')
9
+ @token = Picky::Query::Token.processed('some_text~', 'Some Original~')
10
10
  @category = stub :category, :bundle_for => @bundle, :name => :some_category_name
11
11
 
12
12
  @combination = described_class.new @token, @category
@@ -41,7 +41,7 @@ describe Picky::Query::Combination do
41
41
  describe 'to_result' do
42
42
  context 'functional with qualifier' do
43
43
  before(:each) do
44
- token = Picky::Tokenizers::Query.new.tokenize('name:Blä~').first
44
+ token = Picky::Query::Token.processed 'name:blä~', 'Blä~'
45
45
 
46
46
  @combination = Picky::Query::Combination.new token, @category
47
47
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Picky::Query::Combinations::Base do
5
+ describe Picky::Query::Combinations do
6
6
 
7
7
  before(:each) do
8
8
  @combinations_ary = stub :combinations_ary
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Query::IndexesCheck do
4
+
5
+ describe 'check_backend_types' do
6
+ before(:each) do
7
+ @redis = stub :redis, :backend => Picky::Backends::Redis.new
8
+ @memory = stub :memory, :backend => Picky::Backends::Memory.new
9
+ end
10
+ it 'does not raise on the same type' do
11
+ described_class.check_backend_types [@redis, @redis]
12
+ end
13
+ it 'raises on multiple types' do
14
+ expect do
15
+ described_class.check_backend_types [@redis, @memory]
16
+ end.to raise_error(Picky::Query::DifferentTypesError)
17
+ end
18
+ it 'raises with the right message on multiple types' do
19
+ expect do
20
+ described_class.check_backend_types [@redis, @memory]
21
+ end.to raise_error("Currently it isn't possible to mix Indexes with backends Picky::Backends::Redis and Picky::Backends::Memory in the same Search instance.")
22
+ end
23
+ end
24
+
25
+ end
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Picky::Query::Indexes do
4
-
4
+
5
+ before(:each) do
6
+ Picky::Query::IndexesCheck.stub! :check_backend_types
7
+ end
8
+
5
9
  3.times do |i|
6
10
  n = i + 1
7
11
  name = :"index#{n}"
@@ -5,10 +5,10 @@ describe Picky::Query::Token do
5
5
 
6
6
  describe '==' do
7
7
  it 'is equal if the originals are equal' do
8
- described_class.processed('similar~').should == described_class.processed('similar~')
8
+ described_class.processed('similar~', 'Similar~').should == described_class.processed('similar~', 'Similar~')
9
9
  end
10
10
  it 'is not equal if the originals are not equal' do
11
- described_class.processed('similar~').should_not == described_class.processed('similar')
11
+ described_class.processed('similar~', 'Similar~').should_not == described_class.processed('similar', 'Similar')
12
12
  end
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ describe Picky::Query::Token do
17
17
  @bundle = stub :bundle, :similar => [:array, :of, :similar]
18
18
  @category = stub :category, :bundle_for => @bundle
19
19
 
20
- @token = described_class.processed 'similar~'
20
+ @token = described_class.processed 'similar~', 'Similar~'
21
21
  end
22
22
  it 'returns the right next tokens' do
23
23
  next_token = @token.next_similar_token @category
@@ -40,7 +40,7 @@ describe Picky::Query::Token do
40
40
  before(:each) do
41
41
  @bundle.stub! :similar => [:array, :of, :similar]
42
42
 
43
- @token = described_class.processed 'similar~'
43
+ @token = described_class.processed 'similar~', 'Similar'
44
44
  end
45
45
  it 'should have a certain original text' do
46
46
  @token.next_similar @bundle
@@ -54,7 +54,7 @@ describe Picky::Query::Token do
54
54
  before(:each) do
55
55
  @bundle.stub! :similar => [:array, :of, :similar]
56
56
 
57
- @token = described_class.processed 'similar~'
57
+ @token = described_class.processed 'similar~', 'Similar'
58
58
  end
59
59
  it 'generates all similar' do
60
60
  @token.next_similar(@bundle).should == :array
@@ -77,7 +77,7 @@ describe Picky::Query::Token do
77
77
  before(:each) do
78
78
  @bundle.stub! :similar => [:array, :of, :similar]
79
79
 
80
- @token = described_class.processed 'nonsimilar'
80
+ @token = described_class.processed 'nonsimilar', 'Nonsimilar'
81
81
  end
82
82
  it 'generates all similar' do
83
83
  @token.next_similar(@bundle).should == nil
@@ -95,7 +95,7 @@ describe Picky::Query::Token do
95
95
  before(:each) do
96
96
  @bundle = stub :bundle
97
97
 
98
- @token = described_class.processed 'flarb~'
98
+ @token = described_class.processed 'flarb~', 'FLARB~'
99
99
  end
100
100
  context "with similar" do
101
101
  before(:each) do
@@ -177,10 +177,10 @@ describe Picky::Query::Token do
177
177
 
178
178
  describe 'processed' do
179
179
  it 'should return a new token' do
180
- described_class.processed('some text').should be_kind_of(described_class)
180
+ described_class.processed('some text', 'SOME TEXT').should be_kind_of(described_class)
181
181
  end
182
182
  it 'generates a token' do
183
- described_class.processed('some text').class.should == described_class
183
+ described_class.processed('some text', 'SOME TEXT').class.should == described_class
184
184
  end
185
185
  end
186
186
 
@@ -191,8 +191,6 @@ describe Picky::Query::Token do
191
191
  end
192
192
  it 'should have an order' do
193
193
  token.should_receive(:qualify).once.ordered
194
- token.should_receive(:extract_original).once.ordered
195
- token.should_receive(:downcase).once.ordered
196
194
  token.should_receive(:partialize).once.ordered
197
195
  token.should_receive(:similarize).once.ordered
198
196
  token.should_receive(:remove_illegals).once.ordered
@@ -205,7 +203,7 @@ describe Picky::Query::Token do
205
203
  describe 'partial?' do
206
204
  context 'similar, partial' do
207
205
  before(:each) do
208
- @token = described_class.processed 'similar~'
206
+ @token = described_class.processed 'similar~', 'Similar~'
209
207
  @token.partial = true
210
208
  end
211
209
  it 'should be false' do
@@ -214,7 +212,7 @@ describe Picky::Query::Token do
214
212
  end
215
213
  context 'similar, not partial' do
216
214
  before(:each) do
217
- @token = described_class.processed 'similar~'
215
+ @token = described_class.processed 'similar~', 'Similar~'
218
216
  end
219
217
  it 'should be false' do
220
218
  @token.partial?.should == false
@@ -222,7 +220,7 @@ describe Picky::Query::Token do
222
220
  end
223
221
  context 'not similar, partial' do
224
222
  before(:each) do
225
- @token = described_class.processed 'not similar'
223
+ @token = described_class.processed 'not similar', 'NOT SIMILAR'
226
224
  @token.partial = true
227
225
  end
228
226
  it 'should be true' do
@@ -231,7 +229,7 @@ describe Picky::Query::Token do
231
229
  end
232
230
  context 'not similar, not partial' do
233
231
  before(:each) do
234
- @token = described_class.processed 'not similar'
232
+ @token = described_class.processed 'not similar', 'NOT SIMILAR'
235
233
  end
236
234
  it 'should be nil' do
237
235
  @token.partial?.should == nil
@@ -241,12 +239,12 @@ describe Picky::Query::Token do
241
239
 
242
240
  describe 'similar' do
243
241
  it 'should not change the original with the text' do
244
- token = described_class.processed "bla~"
242
+ token = described_class.processed "bla~", 'BLA~'
245
243
  token.text.should_not == token.original
246
244
  end
247
245
  def self.it_should_have_similarity text, expected_similarity_value
248
246
  it "should have #{ "no" unless expected_similarity_value } similarity for '#{text}'" do
249
- described_class.processed(text).similar?.should == expected_similarity_value
247
+ described_class.processed(text, text.upcase).similar?.should == expected_similarity_value
250
248
  end
251
249
  end
252
250
  it_should_have_similarity 'name:', nil
@@ -266,7 +264,7 @@ describe Picky::Query::Token do
266
264
 
267
265
  describe 'special cases' do
268
266
  it 'should be blank on ""' do
269
- token = described_class.processed '""'
267
+ token = described_class.processed '""', '""'
270
268
 
271
269
  token.should be_blank
272
270
  end
@@ -274,9 +272,9 @@ describe Picky::Query::Token do
274
272
 
275
273
  describe "original" do
276
274
  it "should keep the original text even when processed" do
277
- token = described_class.processed "I'm the original token text."
275
+ token = described_class.processed "I'm the processed text.", "I'm the original text."
278
276
 
279
- token.original.should == "I'm the original token text."
277
+ token.original.should == "I'm the original text."
280
278
  end
281
279
  end
282
280