picky 3.0.1 → 3.1.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.
- data/lib/picky/application.rb +12 -12
- data/lib/picky/backends/backend.rb +17 -0
- data/lib/picky/{backend → backends}/file/basic.rb +1 -1
- data/lib/picky/{backend → backends}/file/json.rb +1 -1
- data/lib/picky/{backend → backends}/file/marshal.rb +1 -1
- data/lib/picky/{backend → backends}/file/text.rb +1 -1
- data/lib/picky/backends/memory.rb +53 -0
- data/lib/picky/{backend → backends}/redis/basic.rb +9 -14
- data/lib/picky/backends/redis/float_hash.rb +26 -0
- data/lib/picky/{backend → backends}/redis/list_hash.rb +7 -11
- data/lib/picky/{backend → backends}/redis/string_hash.rb +7 -11
- data/lib/picky/backends/redis.rb +87 -0
- data/lib/picky/bundle.rb +107 -11
- data/lib/picky/category.rb +5 -5
- data/lib/picky/index.rb +329 -0
- data/lib/picky/index_indexed.rb +31 -0
- data/lib/picky/index_indexing.rb +161 -0
- data/lib/picky/indexed/bundle.rb +112 -0
- data/lib/picky/indexed/wrappers/exact_first.rb +1 -1
- data/lib/picky/indexers/parallel.rb +2 -1
- data/lib/picky/indexers/serial.rb +2 -1
- data/lib/picky/indexes_indexing.rb +1 -1
- data/lib/picky/indexing/bundle.rb +188 -0
- data/lib/picky/indexing/wrappers/category/location.rb +1 -1
- data/lib/picky/interfaces/live_parameters.rb +8 -8
- data/lib/picky/loader.rb +24 -38
- data/lib/picky/migrations/from_30_to_31.rb +61 -0
- data/lib/picky/query/allocation.rb +10 -5
- data/lib/picky/query/combinations.rb +70 -0
- data/lib/picky/query/indexes.rb +8 -7
- data/lib/picky/query/indexes_check.rb +47 -0
- data/lib/picky/query/token.rb +16 -29
- data/lib/picky/query/tokens.rb +4 -20
- data/lib/picky/search.rb +51 -58
- data/lib/picky/tokenizer.rb +231 -0
- data/lib/picky/tokenizers/location.rb +1 -1
- data/lib/tasks/try.rake +4 -12
- data/lib/tasks/try.rb +37 -0
- data/spec/lib/application_spec.rb +5 -5
- data/spec/lib/{backend → backends}/file/basic_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/json_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/marshal_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/text_spec.rb +1 -1
- data/spec/lib/backends/memory_spec.rb +77 -0
- data/spec/lib/{backend → backends}/redis/basic_spec.rb +19 -21
- data/spec/lib/backends/redis/float_hash_spec.rb +38 -0
- data/spec/lib/backends/redis/list_hash_spec.rb +27 -0
- data/spec/lib/backends/redis/string_hash_spec.rb +38 -0
- data/spec/lib/backends/redis_spec.rb +79 -0
- data/spec/lib/categories_indexed_spec.rb +3 -3
- data/spec/lib/category_indexed_spec.rb +6 -6
- data/spec/lib/category_indexing_spec.rb +1 -1
- data/spec/lib/category_spec.rb +1 -1
- data/spec/lib/frontend_adapters/rack_spec.rb +2 -2
- data/spec/lib/{indexes/index_indexed_spec.rb → index_indexed_spec.rb} +1 -1
- data/spec/lib/{indexes/index_indexing_spec.rb → index_indexing_spec.rb} +1 -1
- data/spec/lib/{indexes/index_spec.rb → index_spec.rb} +1 -1
- data/spec/lib/indexed/{bundle/memory_spec.rb → memory_spec.rb} +18 -18
- data/spec/lib/indexed/wrappers/exact_first_spec.rb +2 -2
- data/spec/lib/indexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +3 -3
- data/spec/lib/indexing/bundle_spec.rb +302 -0
- data/spec/lib/query/allocation_spec.rb +21 -11
- data/spec/lib/query/combination_spec.rb +2 -2
- data/spec/lib/query/{combinations/base_spec.rb → combinations_spec.rb} +1 -1
- data/spec/lib/query/indexes_check_spec.rb +25 -0
- data/spec/lib/query/indexes_spec.rb +5 -1
- data/spec/lib/query/token_spec.rb +18 -20
- data/spec/lib/query/tokens_spec.rb +14 -65
- data/spec/lib/search_spec.rb +36 -37
- data/spec/lib/tasks/try_spec.rb +51 -0
- data/spec/lib/{tokenizers/base_spec.rb → tokenizer_spec.rb} +15 -44
- metadata +64 -81
- data/lib/picky/backend/base.rb +0 -121
- data/lib/picky/backend/files.rb +0 -28
- data/lib/picky/backend/redis.rb +0 -44
- data/lib/picky/indexed/bundle/base.rb +0 -47
- data/lib/picky/indexed/bundle/memory.rb +0 -88
- data/lib/picky/indexed/bundle/redis.rb +0 -91
- data/lib/picky/indexes/index.rb +0 -328
- data/lib/picky/indexes/index_indexed.rb +0 -35
- data/lib/picky/indexes/index_indexing.rb +0 -165
- data/lib/picky/indexes/memory.rb +0 -20
- data/lib/picky/indexes/redis.rb +0 -20
- data/lib/picky/indexing/bundle/base.rb +0 -242
- data/lib/picky/indexing/bundle/memory.rb +0 -26
- data/lib/picky/indexing/bundle/redis.rb +0 -26
- data/lib/picky/query/combinations/base.rb +0 -74
- data/lib/picky/query/combinations/memory.rb +0 -52
- data/lib/picky/query/combinations/redis.rb +0 -90
- data/lib/picky/query.rb +0 -6
- data/lib/picky/tokenizers/base.rb +0 -231
- data/lib/picky/tokenizers/index.rb +0 -34
- data/lib/picky/tokenizers/query.rb +0 -61
- data/spec/lib/backend/files_spec.rb +0 -189
- data/spec/lib/backend/redis/list_hash_spec.rb +0 -40
- data/spec/lib/backend/redis/string_hash_spec.rb +0 -47
- data/spec/lib/backend/redis_spec.rb +0 -170
- data/spec/lib/indexed/bundle/redis_spec.rb +0 -41
- data/spec/lib/indexes/redis_spec.rb +0 -15
- data/spec/lib/indexing/bundle/base_spec.rb +0 -38
- data/spec/lib/indexing/bundle/memory_spec.rb +0 -287
- data/spec/lib/indexing/bundle/redis_spec.rb +0 -283
- data/spec/lib/query/combinations/memory_spec.rb +0 -158
- data/spec/lib/query/combinations/redis_spec.rb +0 -172
- data/spec/lib/tokenizers/index_spec.rb +0 -69
- data/spec/lib/tokenizers/query_spec.rb +0 -121
@@ -1,283 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Indexing::Bundle::Redis do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@index = Picky::Indexes::Memory.new :some_index
|
7
|
-
@category = Picky::Category.new :some_category, @index
|
8
|
-
|
9
|
-
@partial = stub :partial
|
10
|
-
@weights = stub :weights
|
11
|
-
@similarity = stub :similarity
|
12
|
-
end
|
13
|
-
let(:index) { described_class.new :some_name, @category, @weights, @partial, @similarity }
|
14
|
-
|
15
|
-
describe 'raise_cache_missing' do
|
16
|
-
it 'does something' do
|
17
|
-
expect {
|
18
|
-
index.raise_cache_missing :similarity
|
19
|
-
}.to raise_error("Error: The similarity cache for test:some_index:some_category:some_name is missing.")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'warn_cache_small' do
|
24
|
-
it 'warns the user' do
|
25
|
-
index.should_receive(:warn).once.with "Warning: similarity cache for test:some_index:some_category:some_name smaller than 16 bytes."
|
26
|
-
|
27
|
-
index.warn_cache_small :similarity
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'identifier' do
|
32
|
-
it 'should return a specific identifier' do
|
33
|
-
index.identifier.should == 'test:some_index:some_category:some_name'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'initialize_index_for' do
|
38
|
-
context 'token not yet assigned' do
|
39
|
-
before(:each) do
|
40
|
-
index.stub! :inverted => {}
|
41
|
-
end
|
42
|
-
it 'should assign it an empty array' do
|
43
|
-
index.initialize_inverted_index_for :some_token
|
44
|
-
|
45
|
-
index.inverted[:some_token].should == []
|
46
|
-
end
|
47
|
-
end
|
48
|
-
context 'token already assigned' do
|
49
|
-
before(:each) do
|
50
|
-
index.stub! :index => { :some_token => :already_assigned }
|
51
|
-
end
|
52
|
-
it 'should not assign it anymore' do
|
53
|
-
index.initialize_inverted_index_for :some_token
|
54
|
-
|
55
|
-
index.index[:some_token].should == :already_assigned
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'retrieve' do
|
61
|
-
before(:each) do
|
62
|
-
prepared = stub :prepared
|
63
|
-
prepared.should_receive(:retrieve).once.and_yield ' 1234', :some_token
|
64
|
-
index.stub! :prepared => prepared
|
65
|
-
|
66
|
-
@ary = stub :ary
|
67
|
-
inverted = stub :inverted, :[] => @ary
|
68
|
-
index.stub! :inverted => inverted
|
69
|
-
end
|
70
|
-
context 'id key format' do
|
71
|
-
before(:each) do
|
72
|
-
@category.stub! :key_format => :to_i
|
73
|
-
end
|
74
|
-
it 'should call the other methods correctly' do
|
75
|
-
@ary.should_receive(:<<).once.with 1234
|
76
|
-
|
77
|
-
index.retrieve
|
78
|
-
end
|
79
|
-
end
|
80
|
-
context 'other key format' do
|
81
|
-
before(:each) do
|
82
|
-
@category.stub! :key_format => :strip
|
83
|
-
end
|
84
|
-
it 'should call the other methods correctly' do
|
85
|
-
@ary.should_receive(:<<).once.with '1234'
|
86
|
-
|
87
|
-
index.retrieve
|
88
|
-
end
|
89
|
-
end
|
90
|
-
context 'no key format - default' do
|
91
|
-
before(:each) do
|
92
|
-
@category.stub! :key_format => nil
|
93
|
-
end
|
94
|
-
it 'should call the other methods correctly' do
|
95
|
-
@ary.should_receive(:<<).once.with 1234
|
96
|
-
|
97
|
-
index.retrieve
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe 'load_from_prepared_index_file' do
|
103
|
-
it 'should call two methods in order' do
|
104
|
-
index.should_receive(:load_from_prepared_index_generation_message).once.ordered
|
105
|
-
index.should_receive(:clear).once.ordered
|
106
|
-
index.should_receive(:retrieve).once.ordered
|
107
|
-
|
108
|
-
index.load_from_prepared_index_file
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe 'generate_derived' do
|
113
|
-
it 'should call two methods in order' do
|
114
|
-
index.should_receive(:generate_weights).once.ordered
|
115
|
-
index.should_receive(:generate_similarity).once.ordered
|
116
|
-
|
117
|
-
index.generate_derived
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe 'generate_caches_from_memory' do
|
122
|
-
it 'should call two methods in order' do
|
123
|
-
index.should_receive(:cache_from_memory_generation_message).once.ordered
|
124
|
-
index.should_receive(:generate_derived).once.ordered
|
125
|
-
|
126
|
-
index.generate_caches_from_memory
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe 'generate_caches_from_source' do
|
131
|
-
it 'should call two methods in order' do
|
132
|
-
index.should_receive(:load_from_prepared_index_file).once.ordered
|
133
|
-
index.should_receive(:generate_caches_from_memory).once.ordered
|
134
|
-
|
135
|
-
index.generate_caches_from_source
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'dump' do
|
140
|
-
it 'should trigger dumps' do
|
141
|
-
index.stub! :timed_exclaim
|
142
|
-
|
143
|
-
index.should_receive(:dump_inverted).once.with
|
144
|
-
index.should_receive(:dump_weights).once.with
|
145
|
-
index.should_receive(:dump_similarity).once.with
|
146
|
-
index.should_receive(:dump_configuration).once.with
|
147
|
-
|
148
|
-
index.dump
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe 'raise_unless_cache_exists' do
|
153
|
-
it "calls methods in order" do
|
154
|
-
index.should_receive(:raise_unless_index_exists).once.ordered
|
155
|
-
index.should_receive(:raise_unless_similarity_exists).once.ordered
|
156
|
-
|
157
|
-
index.raise_unless_cache_exists
|
158
|
-
end
|
159
|
-
end
|
160
|
-
describe 'raise_unless_index_exists' do
|
161
|
-
context 'partial strategy saved' do
|
162
|
-
before(:each) do
|
163
|
-
strategy = stub :strategy, :saved? => true
|
164
|
-
index.stub! :partial_strategy => strategy
|
165
|
-
end
|
166
|
-
it "calls the methods in order" do
|
167
|
-
index.should_receive(:warn_if_index_small).once.ordered
|
168
|
-
index.should_receive(:raise_unless_index_ok).once.ordered
|
169
|
-
|
170
|
-
index.raise_unless_index_exists
|
171
|
-
end
|
172
|
-
end
|
173
|
-
context 'partial strategy not saved' do
|
174
|
-
before(:each) do
|
175
|
-
strategy = stub :strategy, :saved? => false
|
176
|
-
index.stub! :partial_strategy => strategy
|
177
|
-
end
|
178
|
-
it "calls nothing" do
|
179
|
-
index.should_receive(:warn_if_index_small).never
|
180
|
-
index.should_receive(:raise_unless_index_ok).never
|
181
|
-
|
182
|
-
index.raise_unless_index_exists
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
describe 'raise_unless_similarity_exists' do
|
187
|
-
context 'similarity strategy saved' do
|
188
|
-
before(:each) do
|
189
|
-
strategy = stub :strategy, :saved? => true
|
190
|
-
index.stub! :similarity_strategy => strategy
|
191
|
-
end
|
192
|
-
it "calls the methods in order" do
|
193
|
-
index.should_receive(:warn_if_similarity_small).once.ordered
|
194
|
-
index.should_receive(:raise_unless_similarity_ok).once.ordered
|
195
|
-
|
196
|
-
index.raise_unless_similarity_exists
|
197
|
-
end
|
198
|
-
end
|
199
|
-
context 'similarity strategy not saved' do
|
200
|
-
before(:each) do
|
201
|
-
strategy = stub :strategy, :saved? => false
|
202
|
-
index.stub! :similarity_strategy => strategy
|
203
|
-
end
|
204
|
-
it "calls nothing" do
|
205
|
-
index.should_receive(:warn_if_similarity_small).never
|
206
|
-
index.should_receive(:raise_unless_similarity_ok).never
|
207
|
-
|
208
|
-
index.raise_unless_similarity_exists
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
describe 'warn_if_similarity_small' do
|
213
|
-
let(:backend) { index.backend }
|
214
|
-
context "files similarity cache small" do
|
215
|
-
before(:each) do
|
216
|
-
backend.stub! :similarity_cache_small? => true
|
217
|
-
end
|
218
|
-
it "warns" do
|
219
|
-
index.should_receive(:warn_cache_small).once.with :similarity
|
220
|
-
|
221
|
-
index.warn_if_similarity_small
|
222
|
-
end
|
223
|
-
end
|
224
|
-
context "files similarity cache not small" do
|
225
|
-
before(:each) do
|
226
|
-
backend.stub! :similarity_cache_small? => false
|
227
|
-
end
|
228
|
-
it "does not warn" do
|
229
|
-
index.should_receive(:warn_cache_small).never
|
230
|
-
|
231
|
-
index.warn_if_similarity_small
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
describe 'raise_unless_similarity_ok' do
|
236
|
-
let(:backend) { index.backend }
|
237
|
-
context "files similarity cache ok" do
|
238
|
-
before(:each) do
|
239
|
-
backend.stub! :similarity_cache_ok? => true
|
240
|
-
end
|
241
|
-
it "warns" do
|
242
|
-
index.should_receive(:raise_cache_missing).never
|
243
|
-
|
244
|
-
index.raise_unless_similarity_ok
|
245
|
-
end
|
246
|
-
end
|
247
|
-
context "files similarity cache not ok" do
|
248
|
-
before(:each) do
|
249
|
-
backend.stub! :similarity_cache_ok? => false
|
250
|
-
end
|
251
|
-
it "does not warn" do
|
252
|
-
index.should_receive(:raise_cache_missing).once.with :similarity
|
253
|
-
|
254
|
-
index.raise_unless_similarity_ok
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe 'initialization' do
|
260
|
-
it 'should initialize the index correctly' do
|
261
|
-
index.inverted.should == {}
|
262
|
-
end
|
263
|
-
it 'should initialize the weights index correctly' do
|
264
|
-
index.weights.should == {}
|
265
|
-
end
|
266
|
-
it 'should initialize the similarity index correctly' do
|
267
|
-
index.similarity.should == {}
|
268
|
-
end
|
269
|
-
it 'should initialize the configuration correctly' do
|
270
|
-
index.configuration.should == {}
|
271
|
-
end
|
272
|
-
it 'should initialize the partial strategy correctly' do
|
273
|
-
index.partial_strategy.should == @partial
|
274
|
-
end
|
275
|
-
it 'should initialize the weights strategy correctly' do
|
276
|
-
index.weights_strategy.should == @weights
|
277
|
-
end
|
278
|
-
it 'should initialize the similarity strategy correctly' do
|
279
|
-
index.similarity_strategy.should == @similarity
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
#
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Picky::Query::Combinations::Memory do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@combinations_ary = stub :combinations_ary
|
9
|
-
|
10
|
-
@combinations = described_class.new @combinations_ary
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "to_result" do
|
14
|
-
before(:each) do
|
15
|
-
@combination1 = stub :combination1, :to_result => :result1
|
16
|
-
@combination2 = stub :combination2, :to_result => :result2
|
17
|
-
|
18
|
-
@combinations_ary = [@combination1, @combination2]
|
19
|
-
|
20
|
-
@combinations = described_class.new @combinations_ary
|
21
|
-
end
|
22
|
-
it "resultifies the combinations" do
|
23
|
-
@combinations.to_result.should == [:result1, :result2]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "weighted_score" do
|
28
|
-
it "uses the weights' score method" do
|
29
|
-
weights = stub :weights
|
30
|
-
weights.should_receive(:score_for).once.with @combinations_ary
|
31
|
-
|
32
|
-
@combinations.weighted_score weights
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "total_score" do
|
37
|
-
before(:each) do
|
38
|
-
@combination1 = stub :combination1, :weight => 3.14
|
39
|
-
@combination2 = stub :combination2, :weight => 2.76
|
40
|
-
|
41
|
-
@combinations_ary = [@combination1, @combination2]
|
42
|
-
|
43
|
-
@combinations = described_class.new @combinations_ary
|
44
|
-
end
|
45
|
-
it "sums the scores" do
|
46
|
-
@combinations.total_score.should == 5.90
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "calculate_score" do
|
51
|
-
before(:each) do
|
52
|
-
@combinations.stub! :total_score => 0
|
53
|
-
@combinations.stub! :weighted_score => 0
|
54
|
-
end
|
55
|
-
it "first sums, then weighs" do
|
56
|
-
@combinations.should_receive(:total_score).once.ordered.and_return 0
|
57
|
-
@combinations.should_receive(:weighted_score).once.ordered.and_return 0
|
58
|
-
|
59
|
-
@combinations.calculate_score :anything
|
60
|
-
end
|
61
|
-
it "calls sum_score" do
|
62
|
-
@combinations.should_receive(:total_score).once.with.and_return 0
|
63
|
-
|
64
|
-
@combinations.calculate_score :anything
|
65
|
-
end
|
66
|
-
it "calls sum_score" do
|
67
|
-
@combinations.should_receive(:weighted_score).once.with(:weights).and_return 0
|
68
|
-
|
69
|
-
@combinations.calculate_score :weights
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'hash' do
|
74
|
-
it "delegates to the combinations array" do
|
75
|
-
@combinations_ary.should_receive(:hash).once.with
|
76
|
-
|
77
|
-
@combinations.hash
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'remove' do
|
82
|
-
before(:each) do
|
83
|
-
@combination1 = stub :combination1, :in? => false
|
84
|
-
@combination2 = stub :combination2, :in? => true
|
85
|
-
@combination3 = stub :combination3, :in? => true
|
86
|
-
|
87
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
88
|
-
end
|
89
|
-
it 'should remove the combinations' do
|
90
|
-
@combinations.remove([:any]).should == [@combination1]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe 'keep' do
|
95
|
-
before(:each) do
|
96
|
-
@combination1 = stub :combination1, :in? => false
|
97
|
-
@combination2 = stub :combination2, :in? => true
|
98
|
-
@combination3 = stub :combination3, :in? => true
|
99
|
-
|
100
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
101
|
-
end
|
102
|
-
it 'should filter the combinations' do
|
103
|
-
@combinations.keep([:any]).should == [@combination2, @combination3]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "ids" do
|
108
|
-
before(:each) do
|
109
|
-
@combination1 = stub :combination1
|
110
|
-
@combination2 = stub :combination2
|
111
|
-
@combination3 = stub :combination3
|
112
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
113
|
-
end
|
114
|
-
it "should intersect correctly" do
|
115
|
-
@combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
|
116
|
-
@combination2.should_receive(:ids).once.with.and_return (1..100).to_a
|
117
|
-
@combination3.should_receive(:ids).once.with.and_return (1..10).to_a
|
118
|
-
|
119
|
-
@combinations.ids(:any, :thing).should == (1..10).to_a
|
120
|
-
end
|
121
|
-
it "should intersect symbol_keys correctly" do
|
122
|
-
@combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
|
123
|
-
@combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
|
124
|
-
@combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
|
125
|
-
|
126
|
-
@combinations.ids(:any, :thing).should == (:'00001'..:'0010').to_a
|
127
|
-
end
|
128
|
-
it "should intersect correctly when intermediate intersect result is empty" do
|
129
|
-
@combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
|
130
|
-
@combination2.should_receive(:ids).once.with.and_return (11..100).to_a
|
131
|
-
@combination3.should_receive(:ids).once.with.and_return (1..10).to_a
|
132
|
-
|
133
|
-
@combinations.ids(:any, :thing).should == []
|
134
|
-
end
|
135
|
-
it "should be fast" do
|
136
|
-
@combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
|
137
|
-
@combination2.should_receive(:ids).once.with.and_return (1..100).to_a
|
138
|
-
@combination3.should_receive(:ids).once.with.and_return (1..10).to_a
|
139
|
-
|
140
|
-
performance_of { @combinations.ids(:any, :thing) }.should < 0.004
|
141
|
-
end
|
142
|
-
it "should be fast" do
|
143
|
-
@combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
|
144
|
-
@combination2.should_receive(:ids).once.with.and_return (1..100).to_a
|
145
|
-
@combination3.should_receive(:ids).once.with.and_return (1..10).to_a
|
146
|
-
|
147
|
-
performance_of { @combinations.ids(:any, :thing) }.should < 0.00015
|
148
|
-
end
|
149
|
-
it "should be fast" do
|
150
|
-
@combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
|
151
|
-
@combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
|
152
|
-
@combination3.should_receive(:ids).once.with.and_return (1..10).to_a
|
153
|
-
|
154
|
-
performance_of { @combinations.ids(:any, :thing) }.should < 0.0001
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
@@ -1,172 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
#
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Picky::Query::Combinations::Redis do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@combinations_ary = stub :combinations_ary
|
9
|
-
|
10
|
-
@combinations = described_class.new @combinations_ary
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'ids' do
|
14
|
-
context 'empty combinations' do
|
15
|
-
let(:combinations) { described_class.new [] }
|
16
|
-
it 'does something' do
|
17
|
-
combinations.ids(20,0).should == []
|
18
|
-
end
|
19
|
-
end
|
20
|
-
context 'non-empty' do
|
21
|
-
let(:combination) { stub :combination, :identifier => :some_combination }
|
22
|
-
let(:combinations) { described_class.new [combination] }
|
23
|
-
let(:redis) { stub :redis }
|
24
|
-
before(:each) do
|
25
|
-
combinations.stub! :redis => redis
|
26
|
-
|
27
|
-
combinations.stub! :host => 'some.host'
|
28
|
-
combinations.stub! :pid => 12345
|
29
|
-
end
|
30
|
-
it 'calls the redis backend correctly' do
|
31
|
-
redis.should_receive(:zinterstore).once.ordered.with :"some.host:12345:picky:result", ["some_combination"]
|
32
|
-
redis.should_receive(:zrange).once.ordered.with :"some.host:12345:picky:result", 0, 20
|
33
|
-
redis.should_receive(:del).once.ordered.with :"some.host:12345:picky:result"
|
34
|
-
|
35
|
-
combinations.ids 20,0
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'pid' do
|
41
|
-
it "returns the Process' pid" do
|
42
|
-
Process.stub! :pid => 12345
|
43
|
-
|
44
|
-
@combinations.pid.should == 12345
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'host' do
|
49
|
-
before(:each) do
|
50
|
-
@combinations.class.stub! :extract_host => 'some.host'
|
51
|
-
end
|
52
|
-
it 'returns the host' do
|
53
|
-
@combinations.host.should == 'some.host'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "to_result" do
|
58
|
-
before(:each) do
|
59
|
-
@combination1 = stub :combination1, :to_result => :result1
|
60
|
-
@combination2 = stub :combination2, :to_result => :result2
|
61
|
-
|
62
|
-
@combinations_ary = [@combination1, @combination2]
|
63
|
-
|
64
|
-
@combinations = described_class.new @combinations_ary
|
65
|
-
end
|
66
|
-
it "resultifies the combinations" do
|
67
|
-
@combinations.to_result.should == [:result1, :result2]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "weighted_score" do
|
72
|
-
it "uses the weights' score method" do
|
73
|
-
weights = stub :weights
|
74
|
-
weights.should_receive(:score_for).once.with @combinations_ary
|
75
|
-
|
76
|
-
@combinations.weighted_score weights
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "total_score" do
|
81
|
-
before(:each) do
|
82
|
-
@combination1 = stub :combination1, :weight => 3.14
|
83
|
-
@combination2 = stub :combination2, :weight => 2.76
|
84
|
-
|
85
|
-
@combinations_ary = [@combination1, @combination2]
|
86
|
-
|
87
|
-
@combinations = described_class.new @combinations_ary
|
88
|
-
end
|
89
|
-
it "sums the scores" do
|
90
|
-
@combinations.total_score.should == 5.90
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "calculate_score" do
|
95
|
-
before(:each) do
|
96
|
-
@combinations.stub! :total_score => 0
|
97
|
-
@combinations.stub! :weighted_score => 0
|
98
|
-
end
|
99
|
-
it "first sums, then weighs" do
|
100
|
-
@combinations.should_receive(:total_score).once.ordered.and_return 0
|
101
|
-
@combinations.should_receive(:weighted_score).once.ordered.and_return 0
|
102
|
-
|
103
|
-
@combinations.calculate_score :anything
|
104
|
-
end
|
105
|
-
it "calls sum_score" do
|
106
|
-
@combinations.should_receive(:total_score).once.with.and_return 0
|
107
|
-
|
108
|
-
@combinations.calculate_score :anything
|
109
|
-
end
|
110
|
-
it "calls sum_score" do
|
111
|
-
@combinations.should_receive(:weighted_score).once.with(:weights).and_return 0
|
112
|
-
|
113
|
-
@combinations.calculate_score :weights
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'hash' do
|
118
|
-
it "delegates to the combinations array" do
|
119
|
-
@combinations_ary.should_receive(:hash).once.with
|
120
|
-
|
121
|
-
@combinations.hash
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'remove' do
|
126
|
-
before(:each) do
|
127
|
-
@combination1 = stub :combination1, :in? => false
|
128
|
-
@combination2 = stub :combination2, :in? => true
|
129
|
-
@combination3 = stub :combination3, :in? => true
|
130
|
-
|
131
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
132
|
-
end
|
133
|
-
it 'should remove the combinations' do
|
134
|
-
@combinations.remove([:any]).should == [@combination1]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe 'keep' do
|
139
|
-
before(:each) do
|
140
|
-
@combination1 = stub :combination1, :in? => false
|
141
|
-
@combination2 = stub :combination2, :in? => true
|
142
|
-
@combination3 = stub :combination3, :in? => true
|
143
|
-
|
144
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
145
|
-
end
|
146
|
-
it 'should filter the combinations' do
|
147
|
-
@combinations.keep([:any]).should == [@combination2, @combination3]
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'generate_intermediate_result_id' do
|
152
|
-
it 'returns the correct result id' do
|
153
|
-
@combinations.stub! :host => 'some_hostname'
|
154
|
-
Process.stub! :pid => 12345
|
155
|
-
|
156
|
-
@combinations.generate_intermediate_result_id.should == :'some_hostname:12345:picky:result'
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "ids" do
|
161
|
-
before(:each) do
|
162
|
-
@combination1 = stub :combination1, :identifier => 'cat1'
|
163
|
-
@combination2 = stub :combination2, :identifier => 'cat2'
|
164
|
-
@combination3 = stub :combination3, :identifier => 'cat3'
|
165
|
-
@combinations = described_class.new [@combination1, @combination2, @combination3]
|
166
|
-
end
|
167
|
-
it 'calls the redis client correctly' do
|
168
|
-
# TODO
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Picky::Tokenizers::Index do
|
6
|
-
|
7
|
-
let(:tokenizer) { described_class.new }
|
8
|
-
|
9
|
-
describe "default*" do
|
10
|
-
before(:all) do
|
11
|
-
@old = described_class.default
|
12
|
-
end
|
13
|
-
after(:all) do
|
14
|
-
described_class.default = @old
|
15
|
-
end
|
16
|
-
it "has a reader" do
|
17
|
-
lambda { described_class.default }.should_not raise_error
|
18
|
-
end
|
19
|
-
it "returns by default a new Index" do
|
20
|
-
described_class.default.should be_kind_of(described_class)
|
21
|
-
end
|
22
|
-
it "has a writer" do
|
23
|
-
lambda { described_class.default = :bla }.should_not raise_error
|
24
|
-
end
|
25
|
-
it "returns what has been written, if something has been written" do
|
26
|
-
described_class.default = :some_default
|
27
|
-
|
28
|
-
described_class.default.should == :some_default
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "remove_removes_characters" do
|
33
|
-
it "should not remove ' from a query by default" do
|
34
|
-
tokenizer.remove_illegals("Lugi's").should == "Lugi's"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "reject!" do
|
39
|
-
it "should reject tokens if blank" do
|
40
|
-
tokenizer.reject(['', 'not blank', '']).should == ['not blank']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "tokenize" do
|
45
|
-
describe "normalizing" do
|
46
|
-
def self.it_should_normalize_token(text, expected)
|
47
|
-
it "should handle the #{text} case" do
|
48
|
-
tokenizer.tokenize(text).to_a.should == [expected].compact
|
49
|
-
end
|
50
|
-
end
|
51
|
-
# defaults
|
52
|
-
#
|
53
|
-
it_should_normalize_token 'it_should_not_normalize_by_default', :it_should_not_normalize_by_default
|
54
|
-
end
|
55
|
-
describe "tokenizing" do
|
56
|
-
def self.it_should_tokenize_token(text, expected)
|
57
|
-
it "should handle the #{text} case" do
|
58
|
-
tokenizer.tokenize(text).to_a.should == expected
|
59
|
-
end
|
60
|
-
end
|
61
|
-
# defaults
|
62
|
-
#
|
63
|
-
it_should_tokenize_token "splitting on \\s", [:splitting, :on, :"\\s"]
|
64
|
-
it_should_tokenize_token 'und', [:und]
|
65
|
-
it_should_tokenize_token '7', [:'7']
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|