picky 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/Index_api.rb +10 -3
- data/lib/picky/cacher/partial/substring.rb +4 -4
- data/lib/picky/calculations/location.rb +39 -0
- data/lib/picky/configuration/index.rb +2 -2
- data/lib/picky/extensions/array.rb +0 -8
- data/lib/picky/extensions/symbol.rb +2 -16
- data/lib/picky/generator.rb +0 -2
- data/lib/picky/index/bundle.rb +7 -5
- data/lib/picky/index/file/basic.rb +2 -6
- data/lib/picky/index/files.rb +24 -14
- data/lib/picky/indexed/bundle.rb +7 -14
- data/lib/picky/indexed/category.rb +2 -1
- data/lib/picky/indexed/wrappers/bundle/calculation.rb +35 -0
- data/lib/picky/indexed/wrappers/bundle/location.rb +40 -0
- data/lib/picky/indexed/wrappers/bundle/wrapper.rb +25 -0
- data/lib/picky/indexers/serial.rb +1 -1
- data/lib/picky/indexing/bundle.rb +7 -0
- data/lib/picky/indexing/category.rb +22 -1
- data/lib/picky/loader.rb +10 -0
- data/lib/picky/sources/couch.rb +1 -1
- data/lib/picky/sources/csv.rb +6 -4
- data/lib/picky/sources/db.rb +1 -1
- data/lib/picky/sources/delicious.rb +1 -1
- data/lib/picky/sources/wrappers/base.rb +5 -4
- data/lib/picky/sources/wrappers/location.rb +16 -22
- data/lib/tasks/try.rake +2 -2
- data/spec/lib/calculations/location_spec.rb +35 -0
- data/spec/lib/extensions/array_spec.rb +0 -10
- data/spec/lib/extensions/symbol_spec.rb +1 -69
- data/spec/lib/index/files_spec.rb +54 -34
- data/spec/lib/indexed/bundle_spec.rb +17 -14
- data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +37 -0
- data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +27 -0
- data/spec/lib/indexing/bundle_spec.rb +5 -1
- data/spec/lib/sources/couch_spec.rb +1 -1
- data/spec/lib/sources/csv_spec.rb +41 -11
- data/spec/lib/sources/db_spec.rb +5 -5
- data/spec/lib/sources/delicious_spec.rb +6 -6
- data/spec/lib/sources/wrappers/base_spec.rb +7 -3
- data/spec/lib/sources/wrappers/location_spec.rb +11 -12
- metadata +13 -3
@@ -8,19 +8,17 @@ module Sources
|
|
8
8
|
|
9
9
|
# TODO Save min and grid!
|
10
10
|
#
|
11
|
-
def initialize
|
12
|
-
super
|
11
|
+
def initialize category, options = {}
|
12
|
+
super category
|
13
13
|
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
17
|
-
@grid = @user_grid / (@precision + 0.5)
|
14
|
+
@precision = extract_precision options
|
15
|
+
@calculation = Calculations::Location.new extract_user_grid(options), @precision
|
18
16
|
end
|
19
17
|
|
20
18
|
#
|
21
19
|
#
|
22
20
|
def extract_user_grid options
|
23
|
-
options[:grid] || raise
|
21
|
+
options[:grid] || raise("Option :grid needs to be passed to a location.")
|
24
22
|
end
|
25
23
|
# Extracts an amount of grids that this
|
26
24
|
# Precision is given in a value.
|
@@ -41,7 +39,7 @@ module Sources
|
|
41
39
|
# Yield the data (id, text for id) for the given type and category.
|
42
40
|
#
|
43
41
|
def harvest type, category
|
44
|
-
|
42
|
+
minimum = 1.0/0
|
45
43
|
|
46
44
|
# Cache. TODO Make option?
|
47
45
|
#
|
@@ -51,36 +49,32 @@ module Sources
|
|
51
49
|
#
|
52
50
|
backend.harvest type, category do |indexed_id, location|
|
53
51
|
location = location.to_f
|
54
|
-
|
52
|
+
minimum = location if location < minimum
|
55
53
|
locations << [indexed_id, location]
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
#
|
60
|
-
marginize
|
56
|
+
@calculation.minimum = minimum
|
61
57
|
|
62
58
|
# Recalculate locations.
|
63
59
|
#
|
64
60
|
locations.each do |indexed_id, location|
|
65
|
-
locations_for(location).each do |new_location|
|
61
|
+
locations_for(@calculation.recalculate(location)).each do |new_location|
|
66
62
|
yield indexed_id, new_location.to_s
|
67
63
|
end
|
68
64
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
|
66
|
+
# TODO Move to the right place.
|
67
|
+
#
|
68
|
+
category.exact[:location_minimum] = minimum
|
73
69
|
end
|
74
70
|
|
75
71
|
# Put location onto multiple places on a grid.
|
76
72
|
#
|
77
73
|
# Note: Always returns an integer.
|
78
74
|
#
|
79
|
-
def locations_for
|
80
|
-
|
81
|
-
|
82
|
-
min_location = new_location - precision
|
83
|
-
max_location = new_location + precision
|
75
|
+
def locations_for repositioned_location
|
76
|
+
min_location = repositioned_location - precision
|
77
|
+
max_location = repositioned_location + precision
|
84
78
|
|
85
79
|
(min_location..max_location).to_a
|
86
80
|
end
|
data/lib/tasks/try.rake
CHANGED
@@ -8,14 +8,14 @@ namespace :try do
|
|
8
8
|
|
9
9
|
tokenizer = index_and_category ? Indexes.find(*index_and_category.split(':')).tokenizer : Tokenizers::Index.default
|
10
10
|
|
11
|
-
puts "\"#{text}\" is index
|
11
|
+
puts "\"#{text}\" is saved in the index as #{tokenizer.tokenize(text.dup).to_a}"
|
12
12
|
end
|
13
13
|
|
14
14
|
# desc "Try how a given word would be tokenized when querying."
|
15
15
|
task :query, [:text] => :application do |_, options|
|
16
16
|
text = options.text
|
17
17
|
|
18
|
-
puts "\"#{text}\"
|
18
|
+
puts "\"#{text}\" as a query will be preprocessed into #{Tokenizers::Query.default.tokenize(text.dup).to_a.map(&:to_s).map(&:to_sym)}"
|
19
19
|
end
|
20
20
|
|
21
21
|
# desc "Try the given text with both the index and the query (type:category optional)."
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Calculations::Location do
|
4
|
+
|
5
|
+
context 'without margin' do
|
6
|
+
before(:each) do
|
7
|
+
@calculation = Calculations::Location.new 3, 1
|
8
|
+
@calculation.minimum = 5
|
9
|
+
end
|
10
|
+
describe 'reposition' do
|
11
|
+
it 'calculates correctly' do
|
12
|
+
@calculation.recalculate(13).should == 5
|
13
|
+
end
|
14
|
+
it 'calculates correctly' do
|
15
|
+
@calculation.recalculate(5).should == 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'without margin' do
|
21
|
+
before(:each) do
|
22
|
+
@calculation = Calculations::Location.new 3, 3
|
23
|
+
@calculation.minimum = 5
|
24
|
+
end
|
25
|
+
describe 'reposition' do
|
26
|
+
it 'calculates correctly' do
|
27
|
+
@calculation.recalculate(13).should == 12
|
28
|
+
end
|
29
|
+
it 'calculates correctly' do
|
30
|
+
@calculation.recalculate(5).should == 3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -7,16 +7,6 @@ describe Array do
|
|
7
7
|
['fish', 'flash', 'flush', 'smooch'].sort_by_levenshtein!(:fush).should == ['fish', 'flush', 'flash', 'smooch']
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
describe 'random' do
|
12
|
-
it 'should choose one element from the array' do
|
13
|
-
left = [1,2,3]
|
14
|
-
100.times do
|
15
|
-
left.delete [1,2,3].random
|
16
|
-
end
|
17
|
-
left.should be_empty
|
18
|
-
end
|
19
|
-
end
|
20
10
|
|
21
11
|
describe "clustered_uniq_fast" do
|
22
12
|
it "should generate a new array" do
|
@@ -7,17 +7,10 @@ describe Symbol do
|
|
7
7
|
before(:each) do
|
8
8
|
@token = (((0..9).to_a)*10).to_s.to_sym
|
9
9
|
end
|
10
|
-
# Note: They influence each other. each_subtoken is faster though.
|
11
|
-
#
|
12
|
-
it 'should be fast' do
|
13
|
-
timed do
|
14
|
-
@token.subtokens
|
15
|
-
end.should < 0.0009
|
16
|
-
end
|
17
10
|
it "should be fast" do
|
18
11
|
timed do
|
19
12
|
@token.each_subtoken do |subtoken| end
|
20
|
-
end.should < 0.
|
13
|
+
end.should < 0.0006
|
21
14
|
end
|
22
15
|
end
|
23
16
|
|
@@ -232,65 +225,4 @@ describe Symbol do
|
|
232
225
|
end
|
233
226
|
end
|
234
227
|
|
235
|
-
describe "subtokens" do
|
236
|
-
context 'normal symbol' do
|
237
|
-
before(:each) do
|
238
|
-
@sym = :reinke
|
239
|
-
end
|
240
|
-
context 'no downto' do
|
241
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
242
|
-
@sym.subtokens.should == [:reinke, :reink, :rein, :rei, :re, :r]
|
243
|
-
end
|
244
|
-
end
|
245
|
-
context 'downto is larger than the symbol' do
|
246
|
-
before(:each) do
|
247
|
-
@downto = 8
|
248
|
-
end
|
249
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
250
|
-
@sym.subtokens(@downto).should == [:reinke]
|
251
|
-
end
|
252
|
-
end
|
253
|
-
context 'downto is exactly the same as symbol' do
|
254
|
-
before(:each) do
|
255
|
-
@downto = 6
|
256
|
-
end
|
257
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
258
|
-
@sym.subtokens(@downto).should == [:reinke]
|
259
|
-
end
|
260
|
-
end
|
261
|
-
context 'downto is smaller than the length of the symbol' do
|
262
|
-
before(:each) do
|
263
|
-
@downto = 4
|
264
|
-
end
|
265
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
266
|
-
@sym.subtokens(@downto).should == [:reinke, :reink, :rein]
|
267
|
-
end
|
268
|
-
end
|
269
|
-
context 'downto is 1' do
|
270
|
-
before(:each) do
|
271
|
-
@downto = 1
|
272
|
-
end
|
273
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
274
|
-
@sym.subtokens(@downto).should == [:reinke, :reink, :rein, :rei, :re, :r]
|
275
|
-
end
|
276
|
-
end
|
277
|
-
context 'downto is 0' do
|
278
|
-
before(:each) do
|
279
|
-
@downto = 0
|
280
|
-
end
|
281
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
282
|
-
@sym.subtokens(@downto).should == [:reinke, :reink, :rein, :rei, :re, :r, :""]
|
283
|
-
end
|
284
|
-
end
|
285
|
-
context 'downto is less than zero' do
|
286
|
-
before(:each) do
|
287
|
-
@downto = -2
|
288
|
-
end
|
289
|
-
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
290
|
-
@sym.subtokens(@downto).should == [:reinke, :reink, :rein]
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
228
|
end
|
@@ -3,17 +3,18 @@ require 'spec_helper'
|
|
3
3
|
describe Index::Files do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
index = stub :index, :name => :some_index
|
7
|
+
category = stub :category, :name => :some_category
|
8
|
+
configuration = Configuration::Index.new index, category
|
9
9
|
|
10
|
-
@files = Index::Files.new :some_name,
|
10
|
+
@files = Index::Files.new :some_name, configuration
|
11
11
|
|
12
12
|
@prepared = @files.prepared
|
13
13
|
|
14
14
|
@index = @files.index
|
15
|
-
@similarity = @files.similarity
|
16
15
|
@weights = @files.weights
|
16
|
+
@similarity = @files.similarity
|
17
|
+
@configuration = @files.configuration
|
17
18
|
end
|
18
19
|
|
19
20
|
describe "retrieve" do
|
@@ -32,6 +33,13 @@ describe Index::Files do
|
|
32
33
|
@files.dump_index :some_hash
|
33
34
|
end
|
34
35
|
end
|
36
|
+
describe "dump_weights" do
|
37
|
+
it "uses the right file" do
|
38
|
+
@weights.should_receive(:dump).once.with :some_hash
|
39
|
+
|
40
|
+
@files.dump_weights :some_hash
|
41
|
+
end
|
42
|
+
end
|
35
43
|
describe "dump_similarity" do
|
36
44
|
it "uses the right file" do
|
37
45
|
@similarity.should_receive(:dump).once.with :some_hash
|
@@ -39,11 +47,11 @@ describe Index::Files do
|
|
39
47
|
@files.dump_similarity :some_hash
|
40
48
|
end
|
41
49
|
end
|
42
|
-
describe "
|
50
|
+
describe "dump_configuration" do
|
43
51
|
it "uses the right file" do
|
44
|
-
@
|
52
|
+
@configuration.should_receive(:dump).once.with :some_hash
|
45
53
|
|
46
|
-
@files.
|
54
|
+
@files.dump_configuration :some_hash
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
@@ -61,6 +69,15 @@ describe Index::Files do
|
|
61
69
|
@files.load_index
|
62
70
|
end
|
63
71
|
end
|
72
|
+
describe "load_weights" do
|
73
|
+
it "uses the right file" do
|
74
|
+
Yajl::Parser.stub! :parse
|
75
|
+
|
76
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r'
|
77
|
+
|
78
|
+
@files.load_weights
|
79
|
+
end
|
80
|
+
end
|
64
81
|
describe "load_similarity" do
|
65
82
|
it "uses the right file" do
|
66
83
|
Marshal.stub! :load
|
@@ -70,61 +87,61 @@ describe Index::Files do
|
|
70
87
|
@files.load_similarity
|
71
88
|
end
|
72
89
|
end
|
73
|
-
describe "
|
90
|
+
describe "load_configuration" do
|
74
91
|
it "uses the right file" do
|
75
92
|
Yajl::Parser.stub! :parse
|
76
93
|
|
77
|
-
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/
|
94
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_configuration.json', 'r'
|
78
95
|
|
79
|
-
@files.
|
96
|
+
@files.load_configuration
|
80
97
|
end
|
81
98
|
end
|
82
99
|
end
|
83
100
|
|
84
101
|
describe "dump indexes" do
|
85
102
|
describe "index_cache_ok?" do
|
86
|
-
it
|
103
|
+
it 'uses the right method' do
|
87
104
|
@index.should_receive(:cache_ok?).once.with
|
88
105
|
|
89
106
|
@files.index_cache_ok?
|
90
107
|
end
|
91
108
|
end
|
92
|
-
describe "similarity_cache_ok?" do
|
93
|
-
it "uses the right method" do
|
94
|
-
@similarity.should_receive(:cache_ok?).once.with
|
95
|
-
|
96
|
-
@files.similarity_cache_ok?
|
97
|
-
end
|
98
|
-
end
|
99
109
|
describe "weights_cache_ok?" do
|
100
|
-
it
|
110
|
+
it 'uses the right method' do
|
101
111
|
@weights.should_receive(:cache_ok?).once.with
|
102
112
|
|
103
113
|
@files.weights_cache_ok?
|
104
114
|
end
|
105
115
|
end
|
116
|
+
describe "similarity_cache_ok?" do
|
117
|
+
it 'uses the right method' do
|
118
|
+
@similarity.should_receive(:cache_ok?).once.with
|
119
|
+
|
120
|
+
@files.similarity_cache_ok?
|
121
|
+
end
|
122
|
+
end
|
106
123
|
end
|
107
124
|
|
108
|
-
describe
|
109
|
-
describe
|
110
|
-
it
|
125
|
+
describe 'dump indexes' do
|
126
|
+
describe 'index_cache_small?' do
|
127
|
+
it 'uses the right method' do
|
111
128
|
@index.should_receive(:cache_small?).once.with
|
112
129
|
|
113
130
|
@files.index_cache_small?
|
114
131
|
end
|
115
132
|
end
|
116
|
-
describe
|
117
|
-
it
|
118
|
-
@
|
133
|
+
describe 'weights_cache_small?' do
|
134
|
+
it 'uses the right method' do
|
135
|
+
@weights.should_receive(:cache_small?).once.with
|
119
136
|
|
120
|
-
@files.
|
137
|
+
@files.weights_cache_small?
|
121
138
|
end
|
122
139
|
end
|
123
|
-
describe
|
124
|
-
it
|
125
|
-
@
|
140
|
+
describe 'similarity_cache_small?' do
|
141
|
+
it 'uses the right method' do
|
142
|
+
@similarity.should_receive(:cache_small?).once.with
|
126
143
|
|
127
|
-
@files.
|
144
|
+
@files.similarity_cache_small?
|
128
145
|
end
|
129
146
|
end
|
130
147
|
end
|
@@ -132,8 +149,9 @@ describe Index::Files do
|
|
132
149
|
describe 'backup' do
|
133
150
|
it 'should call backup on all' do
|
134
151
|
@index.should_receive(:backup).once.with
|
135
|
-
@similarity.should_receive(:backup).once.with
|
136
152
|
@weights.should_receive(:backup).once.with
|
153
|
+
@similarity.should_receive(:backup).once.with
|
154
|
+
@configuration.should_receive(:backup).once.with
|
137
155
|
|
138
156
|
@files.backup
|
139
157
|
end
|
@@ -141,8 +159,9 @@ describe Index::Files do
|
|
141
159
|
describe 'restore' do
|
142
160
|
it 'should call delete on all' do
|
143
161
|
@index.should_receive(:restore).once.with
|
144
|
-
@similarity.should_receive(:restore).once.with
|
145
162
|
@weights.should_receive(:restore).once.with
|
163
|
+
@similarity.should_receive(:restore).once.with
|
164
|
+
@configuration.should_receive(:restore).once.with
|
146
165
|
|
147
166
|
@files.restore
|
148
167
|
end
|
@@ -150,8 +169,9 @@ describe Index::Files do
|
|
150
169
|
describe 'delete' do
|
151
170
|
it 'should call delete on all' do
|
152
171
|
@index.should_receive(:delete).once.with
|
153
|
-
@similarity.should_receive(:delete).once.with
|
154
172
|
@weights.should_receive(:delete).once.with
|
173
|
+
@similarity.should_receive(:delete).once.with
|
174
|
+
@configuration.should_receive(:delete).once.with
|
155
175
|
|
156
176
|
@files.delete
|
157
177
|
end
|
@@ -18,16 +18,6 @@ describe Indexed::Bundle do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe 'load_from_index_file' do
|
22
|
-
it 'should call two methods in order' do
|
23
|
-
@bundle.should_receive(:load_from_index_generation_message).once.ordered
|
24
|
-
@bundle.should_receive(:clear).once.ordered
|
25
|
-
@bundle.should_receive(:retrieve).once.ordered
|
26
|
-
|
27
|
-
@bundle.load_from_index_file
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
21
|
describe 'ids' do
|
32
22
|
before(:each) do
|
33
23
|
@bundle.instance_variable_set :@index, { :existing => :some_ids }
|
@@ -55,8 +45,9 @@ describe Indexed::Bundle do
|
|
55
45
|
describe 'load' do
|
56
46
|
it 'should trigger loads' do
|
57
47
|
@bundle.should_receive(:load_index).once.with
|
58
|
-
@bundle.should_receive(:load_similarity).once.with
|
59
48
|
@bundle.should_receive(:load_weights).once.with
|
49
|
+
@bundle.should_receive(:load_similarity).once.with
|
50
|
+
@bundle.should_receive(:load_configuration).once.with
|
60
51
|
|
61
52
|
@bundle.load
|
62
53
|
end
|
@@ -74,6 +65,15 @@ describe Indexed::Bundle do
|
|
74
65
|
@bundle.load_index
|
75
66
|
end
|
76
67
|
end
|
68
|
+
describe "load_weights" do
|
69
|
+
it "uses the right file" do
|
70
|
+
Yajl::Parser.stub! :parse
|
71
|
+
|
72
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r'
|
73
|
+
|
74
|
+
@bundle.load_weights
|
75
|
+
end
|
76
|
+
end
|
77
77
|
describe "load_similarity" do
|
78
78
|
it "uses the right file" do
|
79
79
|
Marshal.stub! :load
|
@@ -83,13 +83,13 @@ describe Indexed::Bundle do
|
|
83
83
|
@bundle.load_similarity
|
84
84
|
end
|
85
85
|
end
|
86
|
-
describe "
|
86
|
+
describe "load_configuration" do
|
87
87
|
it "uses the right file" do
|
88
88
|
Yajl::Parser.stub! :parse
|
89
89
|
|
90
|
-
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/
|
90
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_configuration.json', 'r'
|
91
91
|
|
92
|
-
@bundle.
|
92
|
+
@bundle.load_configuration
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -111,6 +111,9 @@ describe Indexed::Bundle do
|
|
111
111
|
it 'should initialize the similarity index correctly' do
|
112
112
|
@bundle.similarity.should == {}
|
113
113
|
end
|
114
|
+
it 'should initialize the configuration correctly' do
|
115
|
+
@bundle.configuration.should == {}
|
116
|
+
end
|
114
117
|
it 'should initialize the similarity strategy correctly' do
|
115
118
|
@bundle.similarity_strategy.should == :similarity
|
116
119
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Indexed::Wrappers::Bundle::Calculation do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@bundle = stub :bundle
|
7
|
+
|
8
|
+
@calculation = Indexed::Wrappers::Bundle::Calculation.new @bundle
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'ids' do
|
12
|
+
it 'calls bundle#ids correctly' do
|
13
|
+
@bundle.should_receive(:ids).once.with :'0.0'
|
14
|
+
|
15
|
+
@calculation.ids :some_sym
|
16
|
+
end
|
17
|
+
it 'calls bundle#ids correctly' do
|
18
|
+
@bundle.should_receive(:ids).once.with :'6.28'
|
19
|
+
|
20
|
+
@calculation.ids :'6.28'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'weight' do
|
25
|
+
it 'calls bundle#ids correctly' do
|
26
|
+
@bundle.should_receive(:weight).once.with :'0.0'
|
27
|
+
|
28
|
+
@calculation.weight :some_sym
|
29
|
+
end
|
30
|
+
it 'calls bundle#ids correctly' do
|
31
|
+
@bundle.should_receive(:weight).once.with :'6.28'
|
32
|
+
|
33
|
+
@calculation.weight :'6.28'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Indexed::Wrappers::Bundle::Wrapper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@bundle = stub :bundle
|
7
|
+
|
8
|
+
@calculation = Indexed::Wrappers::Bundle::Wrapper.new @bundle
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'ids' do
|
12
|
+
it 'calls bundle#ids correctly' do
|
13
|
+
@bundle.should_receive(:ids).once.with :some_sym
|
14
|
+
|
15
|
+
@calculation.ids :some_sym
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'weight' do
|
20
|
+
it 'calls bundle#ids correctly' do
|
21
|
+
@bundle.should_receive(:weight).once.with :some_sym
|
22
|
+
|
23
|
+
@calculation.weight :some_sym
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -94,8 +94,9 @@ describe Indexing::Bundle do
|
|
94
94
|
describe 'dump' do
|
95
95
|
it 'should trigger dumps' do
|
96
96
|
@index.should_receive(:dump_index).once.with
|
97
|
-
@index.should_receive(:dump_similarity).once.with
|
98
97
|
@index.should_receive(:dump_weights).once.with
|
98
|
+
@index.should_receive(:dump_similarity).once.with
|
99
|
+
@index.should_receive(:dump_configuration).once.with
|
99
100
|
|
100
101
|
@index.dump
|
101
102
|
end
|
@@ -222,6 +223,9 @@ describe Indexing::Bundle do
|
|
222
223
|
it 'should initialize the similarity index correctly' do
|
223
224
|
@index.similarity.should == {}
|
224
225
|
end
|
226
|
+
it 'should initialize the configuration correctly' do
|
227
|
+
@index.configuration.should == {}
|
228
|
+
end
|
225
229
|
it 'should initialize the partial strategy correctly' do
|
226
230
|
@index.partial_strategy.should == @partial
|
227
231
|
end
|
@@ -1,7 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
describe Sources::CSV do
|
4
5
|
|
6
|
+
describe 'without separator' do
|
7
|
+
before(:each) do
|
8
|
+
@source = Sources::CSV.new :a, :b, :c, :file => :some_file
|
9
|
+
end
|
10
|
+
it 'calls foreach correctly' do
|
11
|
+
block = lambda { |*args| }
|
12
|
+
|
13
|
+
::CSV.should_receive(:foreach).once.with :some_file, {}, &block
|
14
|
+
|
15
|
+
@source.get_data &block
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe 'with separator' do
|
19
|
+
before(:each) do
|
20
|
+
@source = Sources::CSV.new :a, :b, :c, :file => :some_file, :col_sep => 'some_separator'
|
21
|
+
end
|
22
|
+
it 'calls foreach correctly' do
|
23
|
+
block = lambda { |*args| }
|
24
|
+
|
25
|
+
::CSV.should_receive(:foreach).once.with :some_file, :col_sep => 'some_separator', &block
|
26
|
+
|
27
|
+
@source.get_data &block
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
5
31
|
context "without file" do
|
6
32
|
it "should fail correctly" do
|
7
33
|
lambda { @source = Sources::CSV.new(:a, :b, :c) }.should raise_error(Sources::NoCSVFileGiven)
|
@@ -9,21 +35,25 @@ describe Sources::CSV do
|
|
9
35
|
end
|
10
36
|
context "with file" do
|
11
37
|
before(:each) do
|
12
|
-
@source = Sources::CSV.new :a, :b, :c, :file => :some_file
|
13
38
|
::CSV.should_receive(:foreach).any_number_of_times.and_yield ['7', 'a data', 'b data', 'c data']
|
14
39
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
40
|
+
context 'without separator' do
|
41
|
+
before(:each) do
|
42
|
+
@source = Sources::CSV.new :a, :b, :c, :file => :some_file
|
43
|
+
end
|
44
|
+
describe "harvest" do
|
45
|
+
it "should yield the right data" do
|
46
|
+
field = stub :b, :from => :b
|
47
|
+
@source.harvest :anything, field do |id, token|
|
48
|
+
[id, token].should == [7, 'b data']
|
49
|
+
end
|
20
50
|
end
|
21
51
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
52
|
+
describe "get_data" do
|
53
|
+
it "should yield each line" do
|
54
|
+
@source.get_data do |data|
|
55
|
+
data.should == ['7', 'a data', 'b data', 'c data']
|
56
|
+
end
|
27
57
|
end
|
28
58
|
end
|
29
59
|
end
|