picky 3.6.13 → 3.6.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/query/allocations.rb +1 -2
- data/lib/picky/search.rb +8 -8
- data/spec/functional/terminate_early_spec.rb +59 -7
- data/spec/lib/query/allocations_spec.rb +101 -8
- metadata +20 -20
@@ -72,7 +72,6 @@ module Picky
|
|
72
72
|
# Note: It's possible that no ids are returned by an allocation, but a count. (In case of an offset)
|
73
73
|
#
|
74
74
|
def process! amount, offset = 0, terminate_early = nil
|
75
|
-
current_offset = 0
|
76
75
|
each do |allocation|
|
77
76
|
ids = allocation.process! amount, offset
|
78
77
|
if ids.empty?
|
@@ -82,7 +81,7 @@ module Picky
|
|
82
81
|
offset = 0 # we have already passed the offset
|
83
82
|
end
|
84
83
|
if terminate_early
|
85
|
-
break if terminate_early
|
84
|
+
break if terminate_early <= 0 && amount <= 0
|
86
85
|
terminate_early -= 1
|
87
86
|
end
|
88
87
|
end
|
data/lib/picky/search.rb
CHANGED
@@ -5,8 +5,8 @@ module Picky
|
|
5
5
|
# = Picky Searches
|
6
6
|
#
|
7
7
|
# A Picky Search is an object which:
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# * holds one or more indexes
|
9
|
+
# * offers an interface to query these indexes.
|
10
10
|
#
|
11
11
|
# You connect URL paths to indexes via a Query.
|
12
12
|
#
|
@@ -84,14 +84,14 @@ module Picky
|
|
84
84
|
# (So, early)
|
85
85
|
#
|
86
86
|
# Important note: Do not use this for the live search!
|
87
|
-
#
|
87
|
+
# (As Picky needs to calculate the total)
|
88
88
|
#
|
89
89
|
# Note: When using the Picky interface, do not terminate too
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
90
|
+
# early as this will kill off the allocation selections.
|
91
|
+
# A value of
|
92
|
+
# early_terminate 5
|
93
|
+
# is probably a good idea to show the user 5 extra
|
94
|
+
# beyond the needed ones.
|
95
95
|
#
|
96
96
|
# Examples:
|
97
97
|
# # Terminate if you have enough ids.
|
@@ -23,6 +23,9 @@ describe 'Search#terminate_early' do
|
|
23
23
|
try = Picky::Search.new index
|
24
24
|
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
|
25
25
|
|
26
|
+
try = Picky::Search.new index
|
27
|
+
try.search('hello', 30).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
|
28
|
+
|
26
29
|
try = Picky::Search.new index do
|
27
30
|
terminate_early
|
28
31
|
end
|
@@ -37,21 +40,33 @@ describe 'Search#terminate_early' do
|
|
37
40
|
terminate_early with_extra_allocations: 0
|
38
41
|
end
|
39
42
|
try.search('hello', 9).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4]
|
43
|
+
try.search('hello', 9, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
|
44
|
+
try.search('hello', 9, 7).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
|
45
|
+
try.search('hello', 9, 10).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
|
46
|
+
try.search('hello', 9, 13).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
|
47
|
+
try.search('hello', 9, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
|
48
|
+
try.search('hello', 9, 19).ids.should == [5, 4, 3, 2, 1]
|
49
|
+
try.search('hello', 9, 22).ids.should == [2, 1]
|
50
|
+
try.search('hello', 9, 25).ids.should == []
|
40
51
|
|
41
52
|
try = Picky::Search.new index do
|
42
53
|
terminate_early 0
|
43
54
|
end
|
44
|
-
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
|
55
|
+
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
|
45
56
|
|
46
57
|
try = Picky::Search.new index do
|
47
58
|
terminate_early with_extra_allocations: 0
|
48
59
|
end
|
49
|
-
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
|
60
|
+
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
|
50
61
|
|
51
62
|
try = Picky::Search.new index do
|
52
63
|
terminate_early 2
|
53
64
|
end
|
54
65
|
try.search('hello', 13).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6]
|
66
|
+
try.search('hello', 13, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]
|
67
|
+
try.search('hello', 13, 8).ids.should == [4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4]
|
68
|
+
try.search('hello', 13, 12).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
|
69
|
+
try.search('hello', 13, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
|
55
70
|
|
56
71
|
try = Picky::Search.new index do
|
57
72
|
terminate_early with_extra_allocations: 2
|
@@ -63,18 +78,55 @@ describe 'Search#terminate_early' do
|
|
63
78
|
end
|
64
79
|
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
|
65
80
|
|
81
|
+
GC.start
|
82
|
+
|
83
|
+
try_slow = Picky::Search.new index
|
66
84
|
slow = performance_of do
|
67
|
-
|
85
|
+
try_slow.search 'hello'
|
86
|
+
end
|
87
|
+
try_fast = Picky::Search.new index do
|
88
|
+
terminate_early
|
68
89
|
end
|
90
|
+
fast = performance_of do
|
91
|
+
try_fast.search 'hello'
|
92
|
+
end
|
93
|
+
(slow/fast).should >= 1.1
|
69
94
|
|
70
|
-
|
95
|
+
try_slow = Picky::Search.new index
|
96
|
+
slow = performance_of do
|
97
|
+
try_slow.search 'hello hello'
|
98
|
+
end
|
99
|
+
try_fast = Picky::Search.new index do
|
100
|
+
terminate_early
|
101
|
+
end
|
102
|
+
fast = performance_of do
|
103
|
+
try_fast.search 'hello hello'
|
104
|
+
end
|
105
|
+
(slow/fast).should >= 1.4
|
106
|
+
|
107
|
+
try_slow = Picky::Search.new index
|
108
|
+
slow = performance_of do
|
109
|
+
try_slow.search 'hello hello hello'
|
110
|
+
end
|
111
|
+
try_fast = Picky::Search.new index do
|
112
|
+
terminate_early
|
113
|
+
end
|
114
|
+
fast = performance_of do
|
115
|
+
try_fast.search 'hello hello hello'
|
116
|
+
end
|
117
|
+
(slow/fast).should >= 1.8
|
118
|
+
|
119
|
+
try_slow = Picky::Search.new index
|
120
|
+
slow = performance_of do
|
121
|
+
try_slow.search 'hello hello hello hello'
|
122
|
+
end
|
123
|
+
try_fast = Picky::Search.new index do
|
71
124
|
terminate_early
|
72
125
|
end
|
73
126
|
fast = performance_of do
|
74
|
-
|
127
|
+
try_fast.search 'hello hello hello hello'
|
75
128
|
end
|
76
|
-
|
77
|
-
(slow/fast).should
|
129
|
+
(slow/fast).should >= 2.0
|
78
130
|
end
|
79
131
|
|
80
132
|
end
|
@@ -81,20 +81,20 @@ describe Picky::Query::Allocations do
|
|
81
81
|
|
82
82
|
describe 'process!' do
|
83
83
|
before(:each) do
|
84
|
-
@allocation1 = stub :allocation1, :
|
85
|
-
@allocation2 = stub :allocation2, :
|
86
|
-
@allocation3 = stub :allocation3, :
|
84
|
+
@allocation1 = stub :allocation1, :count => 4 #, ids: [1, 2, 3, 4]
|
85
|
+
@allocation2 = stub :allocation2, :count => 3 #, ids: [5, 6, 7]
|
86
|
+
@allocation3 = stub :allocation3, :count => 2 #, ids: [8, 9]
|
87
87
|
@allocations = described_class.new [@allocation1, @allocation2, @allocation3]
|
88
88
|
end
|
89
89
|
describe 'lazy evaluation' do
|
90
90
|
context 'small amount' do
|
91
91
|
before(:each) do
|
92
|
-
@amount =
|
92
|
+
@amount = 5
|
93
93
|
@offset = 1
|
94
94
|
end
|
95
95
|
it 'should call the process! method right' do
|
96
|
-
@allocation1.should_receive(:process!).once.with(
|
97
|
-
@allocation2.should_receive(:process!).once.with(
|
96
|
+
@allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
|
97
|
+
@allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
|
98
98
|
@allocation3.should_receive(:process!).never
|
99
99
|
|
100
100
|
@allocations.process! @amount, @offset, 0
|
@@ -107,12 +107,103 @@ describe Picky::Query::Allocations do
|
|
107
107
|
end
|
108
108
|
it 'should call the process! method right' do
|
109
109
|
@allocation1.should_receive(:process!).once.with(1,0).and_return [1]
|
110
|
-
@allocation2.should_receive(:process!).
|
110
|
+
@allocation2.should_receive(:process!).never
|
111
111
|
@allocation3.should_receive(:process!).never
|
112
112
|
|
113
113
|
@allocations.process! @amount, @offset, 0
|
114
114
|
end
|
115
115
|
end
|
116
|
+
context 'small amount and early 1' do
|
117
|
+
before(:each) do
|
118
|
+
@amount = 5
|
119
|
+
@offset = 1
|
120
|
+
end
|
121
|
+
it 'should call the process! method right' do
|
122
|
+
@allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
|
123
|
+
@allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
|
124
|
+
@allocation3.should_receive(:process!).never
|
125
|
+
|
126
|
+
@allocations.process! @amount, @offset, 1
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context 'larger amount and early 1' do
|
130
|
+
before(:each) do
|
131
|
+
@amount = 1
|
132
|
+
@offset = 0
|
133
|
+
end
|
134
|
+
it 'should call the process! method right' do
|
135
|
+
@allocation1.should_receive(:process!).once.with(1,0).and_return [1]
|
136
|
+
@allocation2.should_receive(:process!).once.with(0,0).and_return []
|
137
|
+
@allocation3.should_receive(:process!).never
|
138
|
+
|
139
|
+
@allocations.process! @amount, @offset, 1
|
140
|
+
end
|
141
|
+
end
|
142
|
+
context 'larger amount and early 0' do
|
143
|
+
before(:each) do
|
144
|
+
@amount = 4
|
145
|
+
@offset = 0
|
146
|
+
end
|
147
|
+
it 'should call the process! method right' do
|
148
|
+
@allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
|
149
|
+
@allocation2.should_receive(:process!).never
|
150
|
+
@allocation3.should_receive(:process!).never
|
151
|
+
|
152
|
+
@allocations.process! @amount, @offset, 0
|
153
|
+
end
|
154
|
+
end
|
155
|
+
context 'larger amount and early 1' do
|
156
|
+
before(:each) do
|
157
|
+
@amount = 4
|
158
|
+
@offset = 0
|
159
|
+
end
|
160
|
+
it 'should call the process! method right' do
|
161
|
+
@allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
|
162
|
+
@allocation2.should_receive(:process!).once.with(0,0).and_return []
|
163
|
+
@allocation3.should_receive(:process!).never
|
164
|
+
|
165
|
+
@allocations.process! @amount, @offset, 1
|
166
|
+
end
|
167
|
+
end
|
168
|
+
context 'larger amount and early 0' do
|
169
|
+
before(:each) do
|
170
|
+
@amount = 5
|
171
|
+
@offset = 0
|
172
|
+
end
|
173
|
+
it 'should call the process! method right' do
|
174
|
+
@allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
|
175
|
+
@allocation2.should_receive(:process!).once.with(1,0).and_return [5]
|
176
|
+
@allocation3.should_receive(:process!).never
|
177
|
+
|
178
|
+
@allocations.process! @amount, @offset, 0
|
179
|
+
end
|
180
|
+
end
|
181
|
+
context 'larger amount and early 1' do
|
182
|
+
before(:each) do
|
183
|
+
@amount = 5
|
184
|
+
@offset = 0
|
185
|
+
end
|
186
|
+
it 'should call the process! method right' do
|
187
|
+
@allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
|
188
|
+
@allocation2.should_receive(:process!).once.with(1,0).and_return [5]
|
189
|
+
@allocation3.should_receive(:process!).never
|
190
|
+
|
191
|
+
@allocations.process! @amount, @offset, 1
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context 'larger amount and early 1' do
|
195
|
+
before(:each) do
|
196
|
+
@amount = 8
|
197
|
+
@offset = 0
|
198
|
+
end
|
199
|
+
it 'should call the process! method right' do
|
200
|
+
@allocation1.should_receive(:process!).once.with(8,0).and_return [1, 2, 3, 4]
|
201
|
+
@allocation2.should_receive(:process!).once.with(4,0).and_return [5, 6, 7]
|
202
|
+
@allocation3.should_receive(:process!).once.with(1,0).and_return [8]
|
203
|
+
|
204
|
+
@allocations.process! @amount, @offset, 1
|
205
|
+
end
|
206
|
+
end
|
116
207
|
end
|
117
208
|
describe 'amount spanning 3 allocations' do
|
118
209
|
before(:each) do
|
@@ -162,7 +253,8 @@ describe Picky::Query::Allocations do
|
|
162
253
|
end
|
163
254
|
it 'should return certain ids' do
|
164
255
|
@allocation1.should_receive(:process!).once.with(3,0).and_return [1,2,3]
|
165
|
-
@allocation2.should_receive(:process!).once.with(0,0)
|
256
|
+
@allocation2.should_receive(:process!).once.with(0,0).and_return []
|
257
|
+
@allocation3.should_receive(:process!).once.with(0,0).and_return []
|
166
258
|
|
167
259
|
@allocations.process! @amount, @offset
|
168
260
|
end
|
@@ -174,6 +266,7 @@ describe Picky::Query::Allocations do
|
|
174
266
|
it 'should return certain ids' do
|
175
267
|
@allocation1.should_receive(:process!).once.with(3,3).and_return [4]
|
176
268
|
@allocation2.should_receive(:process!).once.with(2,0).and_return [5,6]
|
269
|
+
@allocation3.should_receive(:process!).once.with(0,0).and_return []
|
177
270
|
|
178
271
|
@allocations.process! @amount, @offset
|
179
272
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70226495445320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70226495445320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70226495444480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.6.
|
32
|
+
version: 3.6.14
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70226495444480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70226495443600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70226495443600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack_fast_escape
|
49
|
-
requirement: &
|
49
|
+
requirement: &70226495442880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70226495442880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: text
|
60
|
-
requirement: &
|
60
|
+
requirement: &70226495442020 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70226495442020
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yajl-ruby
|
71
|
-
requirement: &
|
71
|
+
requirement: &70226495441600 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70226495441600
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &70226495441100 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '3.0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70226495441100
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: unicorn
|
93
|
-
requirement: &
|
93
|
+
requirement: &70226495457020 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70226495457020
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: sinatra
|
104
|
-
requirement: &
|
104
|
+
requirement: &70226495456460 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70226495456460
|
113
113
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
114
114
|
email: florian.hanke+picky@gmail.com
|
115
115
|
executables:
|