picky 3.6.16 → 4.0.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/application.rb +1 -1
- data/lib/picky/backends/backend.rb +2 -0
- data/lib/picky/backends/memory.rb +14 -7
- data/lib/picky/backends/{memory → prepared}/text.rb +10 -4
- data/lib/picky/backends/redis/directly_manipulable.rb +3 -5
- data/lib/picky/backends/redis/list.rb +5 -1
- data/lib/picky/backends/sqlite/basic.rb +4 -2
- data/lib/picky/bundle.rb +6 -7
- data/lib/picky/bundle_indexed.rb +2 -2
- data/lib/picky/bundle_realtime.rb +8 -7
- data/lib/picky/categories.rb +0 -1
- data/lib/picky/categories_indexing.rb +14 -0
- data/lib/picky/category.rb +3 -5
- data/lib/picky/category_indexed.rb +2 -5
- data/lib/picky/category_indexing.rb +28 -16
- data/lib/picky/constants.rb +3 -1
- data/lib/picky/frontend_adapters/rack.rb +2 -2
- data/lib/picky/generators/similarity/phonetic.rb +6 -14
- data/lib/picky/generators/strategy.rb +1 -1
- data/lib/picky/generators/weights/runtime.rb +2 -2
- data/lib/picky/helpers/indexing.rb +20 -0
- data/lib/picky/index.rb +7 -10
- data/lib/picky/index_indexed.rb +1 -8
- data/lib/picky/index_indexing.rb +44 -42
- data/lib/picky/indexers/base.rb +5 -6
- data/lib/picky/indexers/parallel.rb +35 -32
- data/lib/picky/indexers/serial.rb +38 -15
- data/lib/picky/indexes_indexed.rb +0 -7
- data/lib/picky/indexes_indexing.rb +16 -19
- data/lib/picky/loader.rb +6 -4
- data/lib/picky/query/allocation.rb +7 -2
- data/lib/picky/query/combination.rb +1 -1
- data/lib/picky/query/indexes.rb +1 -1
- data/lib/picky/query/indexes_check.rb +12 -14
- data/lib/picky/query/token.rb +33 -15
- data/lib/picky/results/exact_first.rb +53 -0
- data/lib/picky/scheduler.rb +43 -0
- data/lib/picky/search.rb +0 -2
- data/lib/picky/sources/csv.rb +2 -3
- data/lib/picky/sources/db.rb +4 -3
- data/lib/picky/sources/mongo.rb +1 -1
- data/lib/picky/tokenizer.rb +0 -4
- data/lib/picky/wrappers/bundle/location.rb +1 -1
- data/lib/picky.rb +2 -2
- data/lib/tasks/index.rake +13 -14
- data/spec/functional/backends/file_spec.rb +2 -4
- data/spec/functional/backends/memory_spec.rb +2 -2
- data/spec/functional/backends/redis_spec.rb +1 -1
- data/spec/functional/exact_first_spec.rb +24 -4
- data/spec/functional/realtime_spec.rb +7 -3
- data/spec/lib/application_spec.rb +30 -30
- data/spec/lib/backends/backend_spec.rb +25 -27
- data/spec/lib/backends/{memory → prepared}/text_spec.rb +1 -1
- data/spec/lib/category_indexing_spec.rb +1 -1
- data/spec/lib/extensions/symbol_spec.rb +1 -1
- data/spec/lib/generators/similarity/phonetic_spec.rb +46 -0
- data/spec/lib/index_indexed_spec.rb +5 -5
- data/spec/lib/index_indexing_spec.rb +13 -12
- data/spec/lib/index_spec.rb +8 -8
- data/spec/lib/indexers/base_spec.rb +5 -6
- data/spec/lib/indexers/parallel_spec.rb +10 -10
- data/spec/lib/indexes_indexed_spec.rb +1 -7
- data/spec/lib/indexes_indexing_spec.rb +10 -5
- data/spec/lib/query/indexes_check_spec.rb +44 -15
- data/spec/lib/query/indexes_spec.rb +11 -11
- data/spec/lib/query/token_spec.rb +10 -0
- data/spec/lib/{indexed/wrappers → results}/exact_first_spec.rb +18 -21
- data/spec/lib/scheduler_spec.rb +92 -0
- metadata +45 -34
- data/lib/picky/cores.rb +0 -127
- data/lib/picky/tokenizers/location.rb +0 -53
- data/lib/picky/wrappers/category/exact_first.rb +0 -94
- data/spec/lib/cores_spec.rb +0 -185
data/spec/lib/cores_spec.rb
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Picky::Cores do
|
5
|
-
|
6
|
-
describe ".forked" do
|
7
|
-
context 'without fork' do
|
8
|
-
before(:each) do
|
9
|
-
Picky::Cores.stub! :fork? => false
|
10
|
-
end
|
11
|
-
it 'should not fork' do
|
12
|
-
Process.should_receive(:fork).never
|
13
|
-
|
14
|
-
described_class.forked([1,2]) do |element|
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
it 'should yield the two elements' do
|
19
|
-
result = []
|
20
|
-
|
21
|
-
described_class.forked([1,2]) do |element|
|
22
|
-
result << element
|
23
|
-
end
|
24
|
-
|
25
|
-
result.should == [1,2]
|
26
|
-
end
|
27
|
-
it 'should yield the two elements' do
|
28
|
-
result = []
|
29
|
-
|
30
|
-
described_class.forked([1,2], randomly: true) do |element|
|
31
|
-
result << element
|
32
|
-
end
|
33
|
-
|
34
|
-
# This test remains like this because I
|
35
|
-
# like the stupidity of it.
|
36
|
-
#
|
37
|
-
if result == [1,2]
|
38
|
-
result.should == [1,2]
|
39
|
-
else
|
40
|
-
result.should == [2,1]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
context 'with forking' do
|
45
|
-
before(:each) do
|
46
|
-
Picky::Cores.stub! :fork? => true
|
47
|
-
Process.should_receive(:fork).any_number_of_times.and_yield
|
48
|
-
end
|
49
|
-
context "with array" do
|
50
|
-
context "with block" do
|
51
|
-
it "runs ok" do
|
52
|
-
# TODO Problematic test. Should not raise the first time
|
53
|
-
#
|
54
|
-
Process.should_receive(:wait).once.and_raise Errno::ECHILD.new
|
55
|
-
|
56
|
-
described_class.forked([1, 2]) do |e|
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
it "yields the elements" do
|
61
|
-
result = []
|
62
|
-
|
63
|
-
described_class.forked([1, 2]) do |e|
|
64
|
-
result << e
|
65
|
-
end
|
66
|
-
|
67
|
-
result.should == [1, 2]
|
68
|
-
end
|
69
|
-
it 'should not fork with amount option' do
|
70
|
-
Process.should_receive(:fork).never
|
71
|
-
|
72
|
-
described_class.forked([1,2], amount: 1) do |element|
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
it 'should not fork with max == 1 option' do
|
77
|
-
Process.should_receive(:fork).never
|
78
|
-
|
79
|
-
described_class.forked([1,2], max: 1) do |element|
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
context "without block" do
|
85
|
-
it "fails" do
|
86
|
-
lambda {
|
87
|
-
described_class.forked [1, 2]
|
88
|
-
}.should raise_error("Block argument needed when running Cores.forked")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
context "with empty array" do
|
93
|
-
context "with block" do
|
94
|
-
it "runs ok" do
|
95
|
-
described_class.forked([]) do
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
context "without block" do
|
101
|
-
it "runs ok" do
|
102
|
-
described_class.forked []
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe 'fork?' do
|
110
|
-
context 'with forking capabilities' do
|
111
|
-
before(:all) do
|
112
|
-
# Process.should_receive(:respond_to?).any_number_of_times.with(:fork).and_return true
|
113
|
-
end
|
114
|
-
it 'returns false' do
|
115
|
-
Picky::Cores.fork?(0).should == false
|
116
|
-
end
|
117
|
-
it 'returns false' do
|
118
|
-
Picky::Cores.fork?(1).should == false
|
119
|
-
end
|
120
|
-
it 'returns true' do
|
121
|
-
Picky::Cores.fork?(2).should == true
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe 'number_of_cores' do
|
127
|
-
before(:each) do
|
128
|
-
@linux = mock(:linux).as_null_object
|
129
|
-
@darwin = mock(:darwin).as_null_object
|
130
|
-
described_class.stub! :os_to_core_mapping => {
|
131
|
-
'linux' => @linux,
|
132
|
-
'darwin' => @darwin
|
133
|
-
}
|
134
|
-
end
|
135
|
-
context 'default' do
|
136
|
-
before(:each) do
|
137
|
-
described_class.stub! :platform => 'mswin'
|
138
|
-
end
|
139
|
-
it 'should return 1' do
|
140
|
-
described_class.number_of_cores.should == 1
|
141
|
-
end
|
142
|
-
end
|
143
|
-
context 'osx' do
|
144
|
-
before(:each) do
|
145
|
-
described_class.stub! :platform => 'i386-darwin9.8.0'
|
146
|
-
end
|
147
|
-
it 'should return whatever darwin returns' do
|
148
|
-
@darwin.stub! :call => '1234'
|
149
|
-
|
150
|
-
described_class.number_of_cores.should == 1234
|
151
|
-
end
|
152
|
-
it 'should call darwin' do
|
153
|
-
@darwin.should_receive(:call).once
|
154
|
-
|
155
|
-
described_class.number_of_cores
|
156
|
-
end
|
157
|
-
it 'should not call linux' do
|
158
|
-
@linux.should_receive(:call).never
|
159
|
-
|
160
|
-
described_class.number_of_cores
|
161
|
-
end
|
162
|
-
end
|
163
|
-
context 'linux' do
|
164
|
-
before(:each) do
|
165
|
-
described_class.stub! :platform => 'x86_64-linux'
|
166
|
-
end
|
167
|
-
it 'should return whatever linux returns' do
|
168
|
-
@linux.stub! :call => '1234'
|
169
|
-
|
170
|
-
described_class.number_of_cores.should == 1234
|
171
|
-
end
|
172
|
-
it 'should call linux' do
|
173
|
-
@linux.should_receive(:call).once
|
174
|
-
|
175
|
-
described_class.number_of_cores
|
176
|
-
end
|
177
|
-
it 'should not call darwin' do
|
178
|
-
@darwin.should_receive(:call).never
|
179
|
-
|
180
|
-
described_class.number_of_cores
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|