picky 0.0.0 → 0.0.2
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/bin/picky +14 -0
- data/lib/bundling.rb +10 -0
- data/lib/constants.rb +9 -0
- data/lib/deployment.rb +212 -0
- data/lib/picky/application.rb +40 -0
- data/lib/picky/cacher/convenience.rb +3 -0
- data/lib/picky/cacher/generator.rb +17 -0
- data/lib/picky/cacher/partial/default.rb +7 -0
- data/lib/picky/cacher/partial/none.rb +19 -0
- data/lib/picky/cacher/partial/strategy.rb +7 -0
- data/lib/picky/cacher/partial/subtoken.rb +91 -0
- data/lib/picky/cacher/partial_generator.rb +15 -0
- data/lib/picky/cacher/similarity/default.rb +7 -0
- data/lib/picky/cacher/similarity/double_levenshtone.rb +73 -0
- data/lib/picky/cacher/similarity/none.rb +25 -0
- data/lib/picky/cacher/similarity/strategy.rb +7 -0
- data/lib/picky/cacher/similarity_generator.rb +15 -0
- data/lib/picky/cacher/weights/default.rb +7 -0
- data/lib/picky/cacher/weights/logarithmic.rb +39 -0
- data/lib/picky/cacher/weights/strategy.rb +7 -0
- data/lib/picky/cacher/weights_generator.rb +15 -0
- data/lib/picky/configuration/configuration.rb +13 -0
- data/lib/picky/configuration/field.rb +68 -0
- data/lib/picky/configuration/indexes.rb +60 -0
- data/lib/picky/configuration/queries.rb +32 -0
- data/lib/picky/configuration/type.rb +52 -0
- data/lib/picky/cores.rb +101 -0
- data/lib/picky/db/configuration.rb +23 -0
- data/lib/picky/ext/ruby19/extconf.rb +7 -0
- data/lib/picky/ext/ruby19/performant.c +339 -0
- data/lib/picky/extensions/array.rb +45 -0
- data/lib/picky/extensions/hash.rb +11 -0
- data/lib/picky/extensions/module.rb +15 -0
- data/lib/picky/extensions/symbol.rb +18 -0
- data/lib/picky/generator.rb +156 -0
- data/lib/picky/helpers/cache.rb +23 -0
- data/lib/picky/helpers/gc.rb +11 -0
- data/lib/picky/helpers/measuring.rb +45 -0
- data/lib/picky/helpers/search.rb +27 -0
- data/lib/picky/index/bundle.rb +328 -0
- data/lib/picky/index/category.rb +109 -0
- data/lib/picky/index/combined.rb +38 -0
- data/lib/picky/index/type.rb +30 -0
- data/lib/picky/indexers/base.rb +77 -0
- data/lib/picky/indexers/default.rb +3 -0
- data/lib/picky/indexers/field.rb +13 -0
- data/lib/picky/indexers/no_source_specified_error.rb +5 -0
- data/lib/picky/indexers/solr.rb +60 -0
- data/lib/picky/indexes.rb +180 -0
- data/lib/picky/initializers/ext.rb +6 -0
- data/lib/picky/initializers/mysql.rb +22 -0
- data/lib/picky/loader.rb +287 -0
- data/lib/picky/loggers/search.rb +19 -0
- data/lib/picky/performant/array.rb +23 -0
- data/lib/picky/query/allocation.rb +82 -0
- data/lib/picky/query/allocations.rb +131 -0
- data/lib/picky/query/base.rb +124 -0
- data/lib/picky/query/combination.rb +69 -0
- data/lib/picky/query/combinations.rb +106 -0
- data/lib/picky/query/combinator.rb +92 -0
- data/lib/picky/query/full.rb +15 -0
- data/lib/picky/query/live.rb +22 -0
- data/lib/picky/query/qualifiers.rb +73 -0
- data/lib/picky/query/solr.rb +77 -0
- data/lib/picky/query/token.rb +215 -0
- data/lib/picky/query/tokens.rb +102 -0
- data/lib/picky/query/weigher.rb +159 -0
- data/lib/picky/query/weights.rb +55 -0
- data/lib/picky/rack/harakiri.rb +37 -0
- data/lib/picky/results/base.rb +103 -0
- data/lib/picky/results/full.rb +19 -0
- data/lib/picky/results/live.rb +19 -0
- data/lib/picky/routing.rb +165 -0
- data/lib/picky/signals.rb +11 -0
- data/lib/picky/solr/schema_generator.rb +73 -0
- data/lib/picky/sources/base.rb +19 -0
- data/lib/picky/sources/csv.rb +30 -0
- data/lib/picky/sources/db.rb +77 -0
- data/lib/picky/tokenizers/base.rb +130 -0
- data/lib/picky/tokenizers/default.rb +3 -0
- data/lib/picky/tokenizers/index.rb +73 -0
- data/lib/picky/tokenizers/query.rb +70 -0
- data/lib/picky/umlaut_substituter.rb +21 -0
- data/lib/picky-tasks.rb +6 -0
- data/lib/picky.rb +18 -0
- data/lib/tasks/application.rake +5 -0
- data/lib/tasks/cache.rake +53 -0
- data/lib/tasks/framework.rake +4 -0
- data/lib/tasks/index.rake +29 -0
- data/lib/tasks/server.rake +48 -0
- data/lib/tasks/shortcuts.rake +13 -0
- data/lib/tasks/solr.rake +36 -0
- data/lib/tasks/spec.rake +11 -0
- data/lib/tasks/statistics.rake +13 -0
- data/lib/tasks/try.rake +29 -0
- data/prototype_project/Gemfile +23 -0
- data/prototype_project/Rakefile +1 -0
- data/prototype_project/app/README +6 -0
- data/prototype_project/app/application.rb +50 -0
- data/prototype_project/app/application.ru +29 -0
- data/prototype_project/app/db.yml +10 -0
- data/prototype_project/app/logging.rb +20 -0
- data/prototype_project/app/unicorn.ru +10 -0
- data/prototype_project/log/README +1 -0
- data/prototype_project/script/console +34 -0
- data/prototype_project/tmp/README +0 -0
- data/prototype_project/tmp/pids/README +0 -0
- data/spec/ext/performant_spec.rb +64 -0
- data/spec/lib/application_spec.rb +61 -0
- data/spec/lib/cacher/partial/subtoken_spec.rb +89 -0
- data/spec/lib/cacher/partial_generator_spec.rb +35 -0
- data/spec/lib/cacher/similarity/double_levenshtone_spec.rb +60 -0
- data/spec/lib/cacher/similarity/none_spec.rb +23 -0
- data/spec/lib/cacher/similarity_generator_spec.rb +22 -0
- data/spec/lib/cacher/weights/logarithmic_spec.rb +30 -0
- data/spec/lib/cacher/weights_generator_spec.rb +21 -0
- data/spec/lib/configuration/configuration_spec.rb +38 -0
- data/spec/lib/configuration/type_spec.rb +49 -0
- data/spec/lib/configuration_spec.rb +8 -0
- data/spec/lib/cores_spec.rb +65 -0
- data/spec/lib/extensions/array_spec.rb +37 -0
- data/spec/lib/extensions/hash_spec.rb +11 -0
- data/spec/lib/extensions/module_spec.rb +27 -0
- data/spec/lib/extensions/symbol_spec.rb +85 -0
- data/spec/lib/generator_spec.rb +135 -0
- data/spec/lib/helpers/cache_spec.rb +35 -0
- data/spec/lib/helpers/gc_spec.rb +71 -0
- data/spec/lib/helpers/measuring_spec.rb +18 -0
- data/spec/lib/helpers/search_spec.rb +50 -0
- data/spec/lib/index/bundle_partial_generation_speed_spec.rb +47 -0
- data/spec/lib/index/bundle_spec.rb +260 -0
- data/spec/lib/index/category_spec.rb +203 -0
- data/spec/lib/indexers/base_spec.rb +73 -0
- data/spec/lib/indexers/field_spec.rb +20 -0
- data/spec/lib/loader_spec.rb +48 -0
- data/spec/lib/loggers/search_spec.rb +19 -0
- data/spec/lib/performant/array_spec.rb +13 -0
- data/spec/lib/query/allocation_spec.rb +194 -0
- data/spec/lib/query/allocations_spec.rb +336 -0
- data/spec/lib/query/base_spec.rb +104 -0
- data/spec/lib/query/combination_spec.rb +90 -0
- data/spec/lib/query/combinations_spec.rb +83 -0
- data/spec/lib/query/combinator_spec.rb +112 -0
- data/spec/lib/query/full_spec.rb +22 -0
- data/spec/lib/query/live_spec.rb +61 -0
- data/spec/lib/query/qualifiers_spec.rb +31 -0
- data/spec/lib/query/solr_spec.rb +51 -0
- data/spec/lib/query/token_spec.rb +297 -0
- data/spec/lib/query/tokens_spec.rb +189 -0
- data/spec/lib/query/weights_spec.rb +47 -0
- data/spec/lib/results/base_spec.rb +233 -0
- data/spec/lib/routing_spec.rb +318 -0
- data/spec/lib/solr/schema_generator_spec.rb +42 -0
- data/spec/lib/sources/db_spec.rb +91 -0
- data/spec/lib/tokenizers/base_spec.rb +61 -0
- data/spec/lib/tokenizers/index_spec.rb +51 -0
- data/spec/lib/tokenizers/query_spec.rb +105 -0
- data/spec/lib/umlaut_substituter_spec.rb +84 -0
- data/spec/specific/speed_spec.rb +55 -0
- metadata +371 -15
- data/README.textile +0 -9
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Index::Bundle do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@category = stub :category, :name => :some_category
|
|
7
|
+
@type = stub :type, :name => :some_type
|
|
8
|
+
@partial_strategy = Cacher::Partial::Subtoken.new :down_to => 1
|
|
9
|
+
@full = Index::Bundle.new :some_name, @category, @type, @partial_strategy, nil, nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def generate_random_keys amount
|
|
13
|
+
alphabet = ('a'..'z').to_a
|
|
14
|
+
(1..amount).to_a.collect! do |n|
|
|
15
|
+
Array.new(20).collect! { alphabet[rand(26)] }.join.to_sym
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
def generate_random_ids amount
|
|
19
|
+
(1..amount).to_a.collect! do |_|
|
|
20
|
+
Array.new(rand(100)+5).collect! do |_|
|
|
21
|
+
rand(5_000_000)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'speed' do
|
|
27
|
+
context 'medium arrays' do
|
|
28
|
+
before(:each) do
|
|
29
|
+
random_keys = generate_random_keys 500
|
|
30
|
+
random_ids = generate_random_ids 500
|
|
31
|
+
@full.index = Hash[random_keys.zip(random_ids)]
|
|
32
|
+
|
|
33
|
+
GC.disable
|
|
34
|
+
end
|
|
35
|
+
after(:each) do
|
|
36
|
+
GC.enable
|
|
37
|
+
GC.start
|
|
38
|
+
end
|
|
39
|
+
it 'should be fast' do
|
|
40
|
+
Benchmark.realtime do
|
|
41
|
+
@full.generate_partial
|
|
42
|
+
end.should <= 0.2
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Index::Bundle do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@category = stub :category, :name => :some_category
|
|
7
|
+
@type = stub :type, :name => :some_type
|
|
8
|
+
@partial = stub :partial
|
|
9
|
+
@weights = stub :weights
|
|
10
|
+
@similarity = stub :similarity
|
|
11
|
+
@index_class = Index::Bundle
|
|
12
|
+
@index = @index_class.new :some_name, @category, @type, @partial, @weights, @similarity
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe 'identifier' do
|
|
16
|
+
it 'should return a specific identifier' do
|
|
17
|
+
@index.identifier.should == 'some_name:some_type:some_category'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'create_directory' do
|
|
22
|
+
it 'should use makedirs to create the necessary directory structure' do
|
|
23
|
+
FileUtils.should_receive(:mkdir_p).once.with 'some/search/root/index/test/some_type'
|
|
24
|
+
|
|
25
|
+
@index.create_directory
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'cache_directory' do
|
|
30
|
+
it 'should be correct' do
|
|
31
|
+
@index.cache_directory.should == 'some/search/root/index/test/some_type'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe 'initialize_index_for' do
|
|
36
|
+
context 'token not yet assigned' do
|
|
37
|
+
before(:each) do
|
|
38
|
+
@index.stub! :index => {}
|
|
39
|
+
end
|
|
40
|
+
it 'should assign it an empty array' do
|
|
41
|
+
@index.initialize_index_for :some_token
|
|
42
|
+
|
|
43
|
+
@index.index[:some_token].should == []
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
context 'token already assigned' do
|
|
47
|
+
before(:each) do
|
|
48
|
+
@index.stub! :index => { :some_token => :already_assigned }
|
|
49
|
+
end
|
|
50
|
+
it 'should not assign it anymore' do
|
|
51
|
+
@index.initialize_index_for :some_token
|
|
52
|
+
|
|
53
|
+
@index.index[:some_token].should == :already_assigned
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# FIXME
|
|
59
|
+
#
|
|
60
|
+
# describe 'retrieve' do
|
|
61
|
+
# it 'should call the other methods correctly' do
|
|
62
|
+
# results = stub :results
|
|
63
|
+
# @index.stub! :execute_query => results
|
|
64
|
+
# @index.should_receive(:extract).once.with results
|
|
65
|
+
#
|
|
66
|
+
# @index.retrieve
|
|
67
|
+
# end
|
|
68
|
+
# end
|
|
69
|
+
|
|
70
|
+
describe 'load_from_index_file' do
|
|
71
|
+
it 'should call two methods in order' do
|
|
72
|
+
@index.should_receive(:clear).once.ordered
|
|
73
|
+
@index.should_receive(:retrieve).once.ordered
|
|
74
|
+
|
|
75
|
+
@index.load_from_index_file
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe 'generate_derived' do
|
|
80
|
+
it 'should call two methods in order' do
|
|
81
|
+
@index.should_receive(:generate_weights).once.ordered
|
|
82
|
+
@index.should_receive(:generate_similarity).once.ordered
|
|
83
|
+
|
|
84
|
+
@index.generate_derived
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe 'generate_caches_from_memory' do
|
|
89
|
+
it 'should call two methods in order' do
|
|
90
|
+
@index.should_receive(:cache_from_memory_generation_message).once.ordered
|
|
91
|
+
@index.should_receive(:generate_derived).once.ordered
|
|
92
|
+
|
|
93
|
+
@index.generate_caches_from_memory
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe 'generate_caches_from_db' do
|
|
98
|
+
it 'should call two methods in order' do
|
|
99
|
+
@index.should_receive(:cache_from_db_generation_message).once.ordered
|
|
100
|
+
@index.should_receive(:load_from_index_file).once.ordered
|
|
101
|
+
@index.should_receive(:generate_caches_from_memory).once.ordered
|
|
102
|
+
|
|
103
|
+
@index.generate_caches_from_db
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe 'ids' do
|
|
108
|
+
before(:each) do
|
|
109
|
+
@index.instance_variable_set :@index, { :existing => :some_ids }
|
|
110
|
+
end
|
|
111
|
+
it 'should return an empty array if not found' do
|
|
112
|
+
@index.ids(:non_existing).should == []
|
|
113
|
+
end
|
|
114
|
+
it 'should return the ids if found' do
|
|
115
|
+
@index.ids(:existing).should == :some_ids
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe 'weight' do
|
|
120
|
+
before(:each) do
|
|
121
|
+
@index.instance_variable_set :@weights, { :existing => :specific }
|
|
122
|
+
end
|
|
123
|
+
it 'should return nil' do
|
|
124
|
+
@index.weight(:non_existing).should == nil
|
|
125
|
+
end
|
|
126
|
+
it 'should return the weight for the text' do
|
|
127
|
+
@index.weight(:existing).should == :specific
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe 'raise_unless_cache_exists' do
|
|
132
|
+
before(:each) do
|
|
133
|
+
@index.stub! :cache_small? => false
|
|
134
|
+
end
|
|
135
|
+
context 'weights cache missing' do
|
|
136
|
+
before(:each) do
|
|
137
|
+
@index.stub! :cache_ok? => true
|
|
138
|
+
@index.stub! :weights_cache_path => 'weights_cache_path'
|
|
139
|
+
@index.should_receive(:cache_ok?).any_number_of_times.with('weights_cache_path').and_return false
|
|
140
|
+
end
|
|
141
|
+
it 'should raise' do
|
|
142
|
+
lambda do
|
|
143
|
+
@index.raise_unless_cache_exists
|
|
144
|
+
end.should raise_error("weights cache for some_name:some_type:some_category missing.")
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
context 'similarity cache missing' do
|
|
148
|
+
before(:each) do
|
|
149
|
+
@index.stub! :cache_ok? => true
|
|
150
|
+
@index.stub! :similarity_cache_path => 'similarity_cache_path'
|
|
151
|
+
@index.should_receive(:cache_ok?).any_number_of_times.with('similarity_cache_path').and_return false
|
|
152
|
+
end
|
|
153
|
+
it 'should raise' do
|
|
154
|
+
lambda do
|
|
155
|
+
@index.raise_unless_cache_exists
|
|
156
|
+
end.should raise_error("similarity cache for some_name:some_type:some_category missing.")
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
context 'index cache missing' do
|
|
160
|
+
before(:each) do
|
|
161
|
+
@index.stub! :cache_ok? => true
|
|
162
|
+
@index.stub! :index_cache_path => 'index_cache_path'
|
|
163
|
+
@index.should_receive(:cache_ok?).any_number_of_times.with('index_cache_path').and_return false
|
|
164
|
+
end
|
|
165
|
+
it 'should raise' do
|
|
166
|
+
lambda do
|
|
167
|
+
@index.raise_unless_cache_exists
|
|
168
|
+
end.should raise_error("index cache for some_name:some_type:some_category missing.")
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
context 'all ok' do
|
|
172
|
+
before(:each) do
|
|
173
|
+
@index.stub! :cache_ok? => true
|
|
174
|
+
end
|
|
175
|
+
it 'should not raise' do
|
|
176
|
+
lambda { @index.raise_unless_cache_exists }.should_not raise_error
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe 'delete_all' do
|
|
182
|
+
it 'should call delete with all paths' do
|
|
183
|
+
@index.should_receive(:delete).once.with @index.index_cache_path
|
|
184
|
+
@index.should_receive(:delete).once.with @index.similarity_cache_path
|
|
185
|
+
@index.should_receive(:delete).once.with @index.weights_cache_path
|
|
186
|
+
|
|
187
|
+
@index.delete_all
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe 'load' do
|
|
192
|
+
it 'should trigger loads' do
|
|
193
|
+
@index.should_receive(:load_index).once.with
|
|
194
|
+
@index.should_receive(:load_similarity).once.with
|
|
195
|
+
@index.should_receive(:load_weights).once.with
|
|
196
|
+
|
|
197
|
+
@index.load
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe 'dump' do
|
|
202
|
+
it 'should trigger dumps' do
|
|
203
|
+
@index.should_receive(:dump_index).once.with
|
|
204
|
+
@index.should_receive(:dump_similarity).once.with
|
|
205
|
+
@index.should_receive(:dump_weights).once.with
|
|
206
|
+
|
|
207
|
+
@index.dump
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
describe 'weights_cache_path' do
|
|
212
|
+
it 'should return the correct file name' do
|
|
213
|
+
@index.weights_cache_path.should == 'some/search/root/index/test/some_type/some_name_some_category_weights.dump'
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
describe 'similarity_cache_path' do
|
|
217
|
+
it 'should return the correct file name' do
|
|
218
|
+
@index.similarity_cache_path.should == 'some/search/root/index/test/some_type/some_name_some_category_similarity.dump'
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
describe 'index_cache_path' do
|
|
222
|
+
it 'should return the correct file name' do
|
|
223
|
+
@index.index_cache_path.should == 'some/search/root/index/test/some_type/some_name_some_category_index.dump'
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
describe 'initialization' do
|
|
228
|
+
before(:each) do
|
|
229
|
+
@index = @index_class.new :some_name, :some_category, :some_type, :partial, :weights, :similarity
|
|
230
|
+
end
|
|
231
|
+
it 'should initialize the index correctly' do
|
|
232
|
+
@index.index.should == {}
|
|
233
|
+
end
|
|
234
|
+
it 'should initialize the weights index correctly' do
|
|
235
|
+
@index.weights.should == {}
|
|
236
|
+
end
|
|
237
|
+
it 'should initialize the similarity index correctly' do
|
|
238
|
+
@index.similarity.should == {}
|
|
239
|
+
end
|
|
240
|
+
it 'should initialize the name correctly' do
|
|
241
|
+
@index.name.should == :some_name
|
|
242
|
+
end
|
|
243
|
+
it 'should initialize the name correctly' do
|
|
244
|
+
@index.category.should == :some_category
|
|
245
|
+
end
|
|
246
|
+
it 'should initialize the name correctly' do
|
|
247
|
+
@index.type.should == :some_type
|
|
248
|
+
end
|
|
249
|
+
it 'should initialize the partial strategy correctly' do
|
|
250
|
+
@index.partial_strategy.should == :partial
|
|
251
|
+
end
|
|
252
|
+
it 'should initialize the weights strategy correctly' do
|
|
253
|
+
@index.weights_strategy.should == :weights
|
|
254
|
+
end
|
|
255
|
+
it 'should initialize the similarity strategy correctly' do
|
|
256
|
+
@index.similarity_strategy.should == :similarity
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Index::Category do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@field = stub :field, :name => :some_name
|
|
7
|
+
@type = stub :type, :name => :some_type
|
|
8
|
+
@partial = stub :partial
|
|
9
|
+
@weights = stub :weights
|
|
10
|
+
@similarity = stub :similarity
|
|
11
|
+
@category = Index::Category.new @field, @type, :partial => @partial, :weights => @weights, :similarity => @similarity
|
|
12
|
+
|
|
13
|
+
@full = stub :full, :dump => nil
|
|
14
|
+
@category.stub! :full => @full
|
|
15
|
+
|
|
16
|
+
@partial = stub :partial, :dump => nil
|
|
17
|
+
@category.stub! :partial => @partial
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'dump_caches' do
|
|
21
|
+
it 'should dump the full index' do
|
|
22
|
+
@full.should_receive(:dump).once.with
|
|
23
|
+
|
|
24
|
+
@category.dump_caches
|
|
25
|
+
end
|
|
26
|
+
it 'should dump the partial index' do
|
|
27
|
+
@partial.should_receive(:dump).once.with
|
|
28
|
+
|
|
29
|
+
@category.dump_caches
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe 'generate_derived_partial' do
|
|
34
|
+
it 'should delegate to partial' do
|
|
35
|
+
@partial.should_receive(:generate_derived).once.with
|
|
36
|
+
|
|
37
|
+
@category.generate_derived_partial
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'generate_derived_full' do
|
|
42
|
+
it 'should delegate to full' do
|
|
43
|
+
@full.should_receive(:generate_derived).once.with
|
|
44
|
+
|
|
45
|
+
@category.generate_derived_full
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe 'generate_indexes_from_full_index' do
|
|
50
|
+
it 'should call three method in order' do
|
|
51
|
+
@category.should_receive(:generate_derived_full).once.with().ordered
|
|
52
|
+
@category.should_receive(:generate_partial).once.with().ordered
|
|
53
|
+
@category.should_receive(:generate_derived_partial).once.with().ordered
|
|
54
|
+
|
|
55
|
+
@category.generate_indexes_from_full_index
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'weight' do
|
|
60
|
+
before(:each) do
|
|
61
|
+
@token = stub :token, :text => :some_text
|
|
62
|
+
end
|
|
63
|
+
context 'partial bundle' do
|
|
64
|
+
before(:each) do
|
|
65
|
+
@category.stub! :bundle_for => @partial
|
|
66
|
+
end
|
|
67
|
+
it 'should receive weight with the token text' do
|
|
68
|
+
@partial.should_receive(:weight).once.with :some_text
|
|
69
|
+
|
|
70
|
+
@category.weight @token
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
context 'full bundle' do
|
|
74
|
+
before(:each) do
|
|
75
|
+
@category.stub! :bundle_for => @full
|
|
76
|
+
end
|
|
77
|
+
it 'should receive weight with the token text' do
|
|
78
|
+
@full.should_receive(:weight).once.with :some_text
|
|
79
|
+
|
|
80
|
+
@category.weight @token
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe 'ids' do
|
|
86
|
+
before(:each) do
|
|
87
|
+
@token = stub :token, :text => :some_text
|
|
88
|
+
end
|
|
89
|
+
context 'partial bundle' do
|
|
90
|
+
before(:each) do
|
|
91
|
+
@category.stub! :bundle_for => @partial
|
|
92
|
+
end
|
|
93
|
+
it 'should receive ids with the token text' do
|
|
94
|
+
@partial.should_receive(:ids).once.with :some_text
|
|
95
|
+
|
|
96
|
+
@category.ids @token
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
context 'full bundle' do
|
|
100
|
+
before(:each) do
|
|
101
|
+
@category.stub! :bundle_for => @full
|
|
102
|
+
end
|
|
103
|
+
it 'should receive ids with the token text' do
|
|
104
|
+
@full.should_receive(:ids).once.with :some_text
|
|
105
|
+
|
|
106
|
+
@category.ids @token
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe 'combination_for' do
|
|
112
|
+
context 'no weight for token' do
|
|
113
|
+
before(:each) do
|
|
114
|
+
@category.stub! :weight => nil
|
|
115
|
+
end
|
|
116
|
+
it 'should return nil' do
|
|
117
|
+
@category.combination_for(:anything).should == nil
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
context 'weight for token' do
|
|
121
|
+
before(:each) do
|
|
122
|
+
@token = stub :token, :text => :some_text
|
|
123
|
+
@category.stub! :weight => :some_weight, :bundle_for => :bundle
|
|
124
|
+
end
|
|
125
|
+
it 'should return a new combination' do
|
|
126
|
+
@category.combination_for(@token).should be_kind_of(::Query::Combination)
|
|
127
|
+
end
|
|
128
|
+
it 'should create the combination correctly' do
|
|
129
|
+
::Query::Combination.should_receive(:new).once.with @token, @category
|
|
130
|
+
|
|
131
|
+
@category.combination_for @token
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe 'bundle_for' do
|
|
137
|
+
it 'should return the right bundle' do
|
|
138
|
+
token = stub :token, :partial? => false
|
|
139
|
+
|
|
140
|
+
@category.bundle_for(token).should == @full
|
|
141
|
+
end
|
|
142
|
+
it 'should return the right bundle' do
|
|
143
|
+
token = stub :token, :partial? => true
|
|
144
|
+
|
|
145
|
+
@category.bundle_for(token).should == @partial
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe 'generate_caches_from_memory' do
|
|
150
|
+
it 'should delegate to partial' do
|
|
151
|
+
@partial.should_receive(:generate_caches_from_memory).once.with
|
|
152
|
+
|
|
153
|
+
@category.generate_caches_from_memory
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe 'generate_partial' do
|
|
158
|
+
it 'should return whatever the partial generation returns' do
|
|
159
|
+
@full.stub! :index
|
|
160
|
+
@partial.stub! :generate_partial_from => :generation_returns
|
|
161
|
+
|
|
162
|
+
@category.generate_partial
|
|
163
|
+
end
|
|
164
|
+
it 'should use the full index to generate the partial index' do
|
|
165
|
+
full_index = stub :full_index
|
|
166
|
+
@full.stub! :index => full_index
|
|
167
|
+
@partial.should_receive(:generate_partial_from).once.with(full_index)
|
|
168
|
+
|
|
169
|
+
@category.generate_partial
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
describe 'generate_caches_from_db' do
|
|
174
|
+
it 'should delegate to full' do
|
|
175
|
+
@full.should_receive(:generate_caches_from_db).once.with
|
|
176
|
+
|
|
177
|
+
@category.generate_caches_from_db
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe 'generate_caches' do
|
|
182
|
+
before(:each) do
|
|
183
|
+
@category.stub! :exclaim
|
|
184
|
+
end
|
|
185
|
+
it 'should call three method in order' do
|
|
186
|
+
@category.should_receive(:generate_caches_from_db).once.with().ordered
|
|
187
|
+
@category.should_receive(:generate_partial).once.with().ordered
|
|
188
|
+
@category.should_receive(:generate_caches_from_memory).once.with().ordered
|
|
189
|
+
|
|
190
|
+
@category.generate_caches
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
describe 'load_from_cache' do
|
|
195
|
+
it 'should call two methods' do
|
|
196
|
+
@full.should_receive(:load).once
|
|
197
|
+
@partial.should_receive(:load).once
|
|
198
|
+
|
|
199
|
+
@category.load_from_cache
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indexers::Base do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@type = stub :type,
|
|
7
|
+
:name => :some_type,
|
|
8
|
+
:snapshot_table_name => :some_prepared_table_name
|
|
9
|
+
@field = stub :field,
|
|
10
|
+
:name => :some_field_name,
|
|
11
|
+
:search_index_file_name => :some_search_index_name,
|
|
12
|
+
:indexed_name => :some_indexed_field_name
|
|
13
|
+
@indexer = Indexers::Base.new @type, @field
|
|
14
|
+
@indexer.stub! :indexing_message
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "tokenizer" do
|
|
18
|
+
it "should delegate to field" do
|
|
19
|
+
@field.should_receive(:tokenizer).once.with
|
|
20
|
+
|
|
21
|
+
@indexer.tokenizer
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'search_index_file_name' do
|
|
26
|
+
it 'should return a specific name' do
|
|
27
|
+
@indexer.search_index_file_name.should == :some_search_index_name
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "index" do
|
|
32
|
+
it "should execute! the indexer" do
|
|
33
|
+
@indexer.should_receive(:process).once.with
|
|
34
|
+
|
|
35
|
+
@indexer.index
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "source" do
|
|
40
|
+
before(:each) do
|
|
41
|
+
@source = stub :source
|
|
42
|
+
end
|
|
43
|
+
context "field has one" do
|
|
44
|
+
before(:each) do
|
|
45
|
+
@field.stub! :source => @source
|
|
46
|
+
end
|
|
47
|
+
it "should return that one" do
|
|
48
|
+
@indexer.source.should == @source
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
context "field doesn't have one" do
|
|
52
|
+
before(:each) do
|
|
53
|
+
@field.stub! :source => nil
|
|
54
|
+
end
|
|
55
|
+
it "should call raise_no_source" do
|
|
56
|
+
@indexer.should_receive(:raise_no_source).once.with
|
|
57
|
+
|
|
58
|
+
@indexer.source
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "raise_no_source" do
|
|
64
|
+
it "should raise" do
|
|
65
|
+
lambda { @indexer.raise_no_source }.should raise_error(Indexers::NoSourceSpecifiedException)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "chunked" do
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Indexers::Field do
|
|
6
|
+
|
|
7
|
+
before(:each) do
|
|
8
|
+
@type = stub :type, :name => :some_type, :snapshot_table_name => :some_prepared_table_name
|
|
9
|
+
@field = stub :field, :indexed_name => :some_indexed_field_name, :name => :some_field_name, :search_index_file_name => :some_index_table
|
|
10
|
+
@strategy = Indexers::Field.new @type, @field
|
|
11
|
+
@strategy.stub! :indexing_message
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "chunksize" do
|
|
15
|
+
it "should be a specific size" do
|
|
16
|
+
@strategy.chunksize.should == 25_000
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Loader do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@loader_path = File.absolute_path("#{File.dirname(__FILE__)}/../../lib/picky/loader.rb")
|
|
7
|
+
Configuration.stub! :apply
|
|
8
|
+
Indexes.stub! :setup
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe 'load_self' do
|
|
12
|
+
before(:each) do
|
|
13
|
+
Loader.stub! :load
|
|
14
|
+
Loader.stub! :exclaim
|
|
15
|
+
end
|
|
16
|
+
after(:each) do
|
|
17
|
+
Loader.load_self
|
|
18
|
+
end
|
|
19
|
+
it 'should load __SELF__' do
|
|
20
|
+
Loader.should_receive(:load).once.with @loader_path
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'reload' do
|
|
25
|
+
before(:each) do
|
|
26
|
+
load @loader_path
|
|
27
|
+
Loader.stub! :exclaim
|
|
28
|
+
Loader.stub! :load_framework
|
|
29
|
+
Loader.stub! :load_application
|
|
30
|
+
Dir.stub! :chdir
|
|
31
|
+
end
|
|
32
|
+
after(:each) do
|
|
33
|
+
Loader.reload
|
|
34
|
+
end
|
|
35
|
+
it 'should call the right methods in order' do
|
|
36
|
+
Loader.should_receive(:load_self).ordered
|
|
37
|
+
Loader.should_receive(:load_framework).ordered
|
|
38
|
+
Loader.should_receive(:load_application).ordered
|
|
39
|
+
end
|
|
40
|
+
it 'should load itself only once' do
|
|
41
|
+
Loader.should_receive(:load_self).once
|
|
42
|
+
end
|
|
43
|
+
# it 'should load the app only once' do
|
|
44
|
+
# Loader.should_receive(:load_framework).once
|
|
45
|
+
# end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Loggers::Search do
|
|
6
|
+
|
|
7
|
+
before(:each) do
|
|
8
|
+
@destination = stub :destination
|
|
9
|
+
@logger = Loggers::Search.new @destination
|
|
10
|
+
end
|
|
11
|
+
describe "log" do
|
|
12
|
+
it "should delegate to info" do
|
|
13
|
+
@destination.should_receive(:info).once.with 'test'
|
|
14
|
+
|
|
15
|
+
@logger.log 'test'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'performant array' do
|
|
4
|
+
|
|
5
|
+
# describe "brute_force_intersect" do
|
|
6
|
+
# it "should intersect correctly" do
|
|
7
|
+
# arys = [[3,4], [1,2,3,4], [3,4,5,8,9]]
|
|
8
|
+
#
|
|
9
|
+
# Performant::Array.brute_force_intersect(arys.sort_by(&:size)).should == [3,4]
|
|
10
|
+
# end
|
|
11
|
+
# end
|
|
12
|
+
|
|
13
|
+
end
|