picky 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,170 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Backend::Redis do
|
4
|
-
|
5
|
-
context 'indexing' do
|
6
|
-
let(:category) do
|
7
|
-
index = stub :index,
|
8
|
-
:name => :some_index,
|
9
|
-
:indexing_bundle_class => Picky::Indexing::Bundle::Memory,
|
10
|
-
:indexed_bundle_class => Picky::Indexed::Bundle::Memory,
|
11
|
-
:identifier => :some_index_identifier
|
12
|
-
Picky::Category.new :some_category, index
|
13
|
-
end
|
14
|
-
let(:bundle) { Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil }
|
15
|
-
let(:redis) { described_class.new bundle }
|
16
|
-
|
17
|
-
describe 'setting' do
|
18
|
-
it 'delegates to the configuration' do
|
19
|
-
configuration = stub :configuration
|
20
|
-
redis.stub! :configuration => configuration
|
21
|
-
|
22
|
-
configuration.should_receive(:member).once.with :some_sym
|
23
|
-
|
24
|
-
redis.setting :some_sym
|
25
|
-
end
|
26
|
-
it 'returns the value' do
|
27
|
-
configuration = stub :configuration
|
28
|
-
redis.stub! :configuration => configuration
|
29
|
-
|
30
|
-
configuration.should_receive(:member).any_number_of_times.and_return "some config"
|
31
|
-
|
32
|
-
redis.setting(:any).should == "some config"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
describe 'weight' do
|
36
|
-
it 'delegates to the weights' do
|
37
|
-
weights = stub :weights
|
38
|
-
redis.stub! :weights => weights
|
39
|
-
|
40
|
-
weights.should_receive(:member).once.with :some_sym
|
41
|
-
|
42
|
-
redis.weight :some_sym
|
43
|
-
end
|
44
|
-
it 'returns a floated value' do
|
45
|
-
weights = stub :weights
|
46
|
-
redis.stub! :weights => weights
|
47
|
-
|
48
|
-
weights.should_receive(:member).any_number_of_times.and_return "1.0"
|
49
|
-
|
50
|
-
redis.weight(:any).should == 1.0
|
51
|
-
end
|
52
|
-
it 'returns a floated value' do
|
53
|
-
weights = stub :weights
|
54
|
-
redis.stub! :weights => weights
|
55
|
-
|
56
|
-
weights.should_receive(:member).any_number_of_times.and_return 1
|
57
|
-
|
58
|
-
redis.weight(:any).should == 1.0
|
59
|
-
end
|
60
|
-
end
|
61
|
-
describe 'ids' do
|
62
|
-
it 'delegates to the index' do
|
63
|
-
inverted = stub :inverted
|
64
|
-
redis.stub! :inverted => inverted
|
65
|
-
|
66
|
-
inverted.should_receive(:collection).once.with :some_sym
|
67
|
-
|
68
|
-
redis.ids :some_sym
|
69
|
-
end
|
70
|
-
it 'returns the value' do
|
71
|
-
inverted = stub :inverted
|
72
|
-
redis.stub! :inverted => inverted
|
73
|
-
|
74
|
-
inverted.should_receive(:collection).any_number_of_times.and_return [1,2,3]
|
75
|
-
|
76
|
-
redis.ids(:any).should == [1,2,3]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'indexed' do
|
82
|
-
let(:category) do
|
83
|
-
index = stub :index,
|
84
|
-
:name => :some_index,
|
85
|
-
:indexing_bundle_class => Picky::Indexing::Bundle::Memory,
|
86
|
-
:indexed_bundle_class => Picky::Indexed::Bundle::Memory,
|
87
|
-
:identifier => :some_index_identifier
|
88
|
-
Picky::Category.new :some_category, index
|
89
|
-
end
|
90
|
-
let(:bundle) { Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil }
|
91
|
-
let(:redis) { described_class.new bundle }
|
92
|
-
|
93
|
-
describe 'setting' do
|
94
|
-
it 'delegates to the configuration' do
|
95
|
-
configuration = stub :configuration
|
96
|
-
redis.stub! :configuration => configuration
|
97
|
-
|
98
|
-
configuration.should_receive(:member).once.with :some_sym
|
99
|
-
|
100
|
-
redis.setting :some_sym
|
101
|
-
end
|
102
|
-
it 'returns the value' do
|
103
|
-
configuration = stub :configuration
|
104
|
-
redis.stub! :configuration => configuration
|
105
|
-
|
106
|
-
configuration.should_receive(:member).any_number_of_times.and_return "some config"
|
107
|
-
|
108
|
-
redis.setting(:any).should == "some config"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
describe 'weight' do
|
112
|
-
it 'delegates to the weights' do
|
113
|
-
weights = stub :weights
|
114
|
-
redis.stub! :weights => weights
|
115
|
-
|
116
|
-
weights.should_receive(:member).once.with :some_sym
|
117
|
-
|
118
|
-
redis.weight :some_sym
|
119
|
-
end
|
120
|
-
it 'returns a floated value' do
|
121
|
-
weights = stub :weights
|
122
|
-
redis.stub! :weights => weights
|
123
|
-
|
124
|
-
weights.should_receive(:member).any_number_of_times.and_return "1.0"
|
125
|
-
|
126
|
-
redis.weight(:any).should == 1.0
|
127
|
-
end
|
128
|
-
it 'returns a floated value' do
|
129
|
-
weights = stub :weights
|
130
|
-
redis.stub! :weights => weights
|
131
|
-
|
132
|
-
weights.should_receive(:member).any_number_of_times.and_return 1
|
133
|
-
|
134
|
-
redis.weight(:any).should == 1.0
|
135
|
-
end
|
136
|
-
end
|
137
|
-
describe 'ids' do
|
138
|
-
it 'delegates to the index' do
|
139
|
-
inverted = stub :inverted
|
140
|
-
redis.stub! :inverted => inverted
|
141
|
-
|
142
|
-
inverted.should_receive(:collection).once.with :some_sym
|
143
|
-
|
144
|
-
redis.ids :some_sym
|
145
|
-
end
|
146
|
-
it 'returns the value' do
|
147
|
-
inverted = stub :inverted
|
148
|
-
redis.stub! :inverted => inverted
|
149
|
-
|
150
|
-
inverted.should_receive(:collection).any_number_of_times.and_return [1,2,3]
|
151
|
-
|
152
|
-
redis.ids(:any).should == [1,2,3]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe 'to_s' do
|
158
|
-
it 'returns the right value' do
|
159
|
-
category = stub :category,
|
160
|
-
:name => :some_category,
|
161
|
-
:identifier => "category_identifier",
|
162
|
-
:prepared_index_path => "prepared/index/path",
|
163
|
-
:index_directory => 'some/index/directory'
|
164
|
-
bundle = Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil
|
165
|
-
|
166
|
-
described_class.new(bundle).to_s.should == "Picky::Backend::Redis(category_identifier:some_bundle)"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Indexed::Bundle::Redis do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@backend = stub :backend
|
7
|
-
|
8
|
-
Picky::Backend::Redis.stub! :new => @backend
|
9
|
-
|
10
|
-
@index = Picky::Indexes::Memory.new :some_index
|
11
|
-
@category = Picky::Category.new :some_category, @index
|
12
|
-
|
13
|
-
@similarity = stub :similarity
|
14
|
-
@bundle = described_class.new :some_name, @category, @similarity
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'ids' do
|
18
|
-
it 'delegates to the backend' do
|
19
|
-
@backend.should_receive(:ids).once.with :some_sym
|
20
|
-
|
21
|
-
@bundle.ids :some_sym
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'weight' do
|
26
|
-
it 'delegates to the backend' do
|
27
|
-
@backend.should_receive(:weight).once.with :some_sym
|
28
|
-
|
29
|
-
@bundle.weight :some_sym
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '[]' do
|
34
|
-
it 'delegates to the backend' do
|
35
|
-
@backend.should_receive(:setting).once.with :some_sym
|
36
|
-
|
37
|
-
@bundle[:some_sym]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Indexing::Bundle::Base do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@category = stub :category,
|
7
|
-
:prepared_index_path => 'prepared/index/path',
|
8
|
-
:identifier => 'some_identifier'
|
9
|
-
Picky::Backend::Files.stub! :new
|
10
|
-
@similarity = Picky::Similarity::DoubleMetaphone.new 3
|
11
|
-
@bundle = described_class.new :some_name, @category, :some_weights, :some_partial, @similarity
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'identifier' do
|
15
|
-
it 'is correct' do
|
16
|
-
@bundle.identifier.should == 'some_identifier:some_name'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'similar' do
|
21
|
-
before(:each) do
|
22
|
-
@bundle.similarity = @similarity.generate_from( :dragon => [1,2,3], :dargon => [4,5,6] )
|
23
|
-
end
|
24
|
-
it 'returns the right similars (not itself)' do
|
25
|
-
@bundle.similar(:dragon).should == [:dargon]
|
26
|
-
end
|
27
|
-
it 'returns the right similars' do
|
28
|
-
@bundle.similar(:trkn).should == [:dragon, :dargon]
|
29
|
-
end
|
30
|
-
it 'performs' do
|
31
|
-
performance_of { @bundle.similar(:dragon) }.should < 0.000075
|
32
|
-
end
|
33
|
-
it 'performs' do
|
34
|
-
performance_of { @bundle.similar(:trkn) }.should < 0.00006
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,287 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Indexing::Bundle::Memory 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! :index => {}
|
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_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
|
-
before(:each) do
|
214
|
-
@backend = index.backend
|
215
|
-
end
|
216
|
-
context "files similarity cache small" do
|
217
|
-
before(:each) do
|
218
|
-
@backend.stub! :similarity_cache_small? => true
|
219
|
-
end
|
220
|
-
it "warns" do
|
221
|
-
index.should_receive(:warn_cache_small).once.with :similarity
|
222
|
-
|
223
|
-
index.warn_if_similarity_small
|
224
|
-
end
|
225
|
-
end
|
226
|
-
context "files similarity cache not small" do
|
227
|
-
before(:each) do
|
228
|
-
@backend.stub! :similarity_cache_small? => false
|
229
|
-
end
|
230
|
-
it "does not warn" do
|
231
|
-
index.should_receive(:warn_cache_small).never
|
232
|
-
|
233
|
-
index.warn_if_similarity_small
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
describe 'raise_unless_similarity_ok' do
|
238
|
-
before(:each) do
|
239
|
-
@backend = index.backend
|
240
|
-
end
|
241
|
-
context "files similarity cache ok" do
|
242
|
-
before(:each) do
|
243
|
-
@backend.stub! :similarity_cache_ok? => true
|
244
|
-
end
|
245
|
-
it "warns" do
|
246
|
-
index.should_receive(:raise_cache_missing).never
|
247
|
-
|
248
|
-
index.raise_unless_similarity_ok
|
249
|
-
end
|
250
|
-
end
|
251
|
-
context "files similarity cache not ok" do
|
252
|
-
before(:each) do
|
253
|
-
@backend.stub! :similarity_cache_ok? => false
|
254
|
-
end
|
255
|
-
it "does not warn" do
|
256
|
-
index.should_receive(:raise_cache_missing).once.with :similarity
|
257
|
-
|
258
|
-
index.raise_unless_similarity_ok
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe 'initialization' do
|
264
|
-
it 'should initialize the index correctly' do
|
265
|
-
index.inverted.should == {}
|
266
|
-
end
|
267
|
-
it 'should initialize the weights index correctly' do
|
268
|
-
index.weights.should == {}
|
269
|
-
end
|
270
|
-
it 'should initialize the similarity index correctly' do
|
271
|
-
index.similarity.should == {}
|
272
|
-
end
|
273
|
-
it 'should initialize the configuration correctly' do
|
274
|
-
index.configuration.should == {}
|
275
|
-
end
|
276
|
-
it 'should initialize the partial strategy correctly' do
|
277
|
-
index.partial_strategy.should == @partial
|
278
|
-
end
|
279
|
-
it 'should initialize the weights strategy correctly' do
|
280
|
-
index.weights_strategy.should == @weights
|
281
|
-
end
|
282
|
-
it 'should initialize the similarity strategy correctly' do
|
283
|
-
index.similarity_strategy.should == @similarity
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|