Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ 3.6.14, ! terminate_early
  • Loading branch information
floere committed Dec 1, 2011
1 parent 6af3b12 commit 2e628bd
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 13 deletions.
4 changes: 4 additions & 0 deletions history.textile
@@ -1,5 +1,9 @@
h2. Upcoming Version

h2. Version 3.6.14

* hanke: (server) Fix for terminate_early with offsets in 3.6.12 (thanks niko!).

h2. Version 3.6.13

* hanke: (server) Fix for exact first matching (thanks geelen!).
Expand Down
3 changes: 1 addition & 2 deletions server/lib/picky/query/allocations.rb
Expand Up @@ -72,7 +72,6 @@ def ids amount = 20
# Note: It's possible that no ids are returned by an allocation, but a count. (In case of an offset)
#
def process! amount, offset = 0, terminate_early = nil
current_offset = 0
each do |allocation|
ids = allocation.process! amount, offset
if ids.empty?
Expand All @@ -82,7 +81,7 @@ def process! amount, offset = 0, terminate_early = nil
offset = 0 # we have already passed the offset
end
if terminate_early
break if terminate_early < 0 && offset <= 0
break if terminate_early <= 0 && amount <= 0
terminate_early -= 1
end
end
Expand Down
19 changes: 17 additions & 2 deletions server/spec/functional/terminate_early_spec.rb
Expand Up @@ -23,6 +23,9 @@
try = Picky::Search.new index
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]

try = Picky::Search.new index
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]

try = Picky::Search.new index do
terminate_early
end
Expand All @@ -37,21 +40,33 @@
terminate_early with_extra_allocations: 0
end
try.search('hello', 9).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4]
try.search('hello', 9, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
try.search('hello', 9, 7).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
try.search('hello', 9, 10).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
try.search('hello', 9, 13).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
try.search('hello', 9, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
try.search('hello', 9, 19).ids.should == [5, 4, 3, 2, 1]
try.search('hello', 9, 22).ids.should == [2, 1]
try.search('hello', 9, 25).ids.should == []

try = Picky::Search.new index do
terminate_early 0
end
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
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]

try = Picky::Search.new index do
terminate_early with_extra_allocations: 0
end
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
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]

try = Picky::Search.new index do
terminate_early 2
end
try.search('hello', 13).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6]
try.search('hello', 13, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]
try.search('hello', 13, 8).ids.should == [4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4]
try.search('hello', 13, 12).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
try.search('hello', 13, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]

try = Picky::Search.new index do
terminate_early with_extra_allocations: 2
Expand Down
109 changes: 101 additions & 8 deletions server/spec/lib/query/allocations_spec.rb
Expand Up @@ -81,20 +81,20 @@

describe 'process!' do
before(:each) do
@allocation1 = stub :allocation1, :process! => [], :count => 4 #, ids: [1, 2, 3, 4]
@allocation2 = stub :allocation2, :process! => [], :count => 3 #, ids: [5, 6, 7]
@allocation3 = stub :allocation3, :process! => [], :count => 2 #, ids: [8, 9]
@allocation1 = stub :allocation1, :count => 4 #, ids: [1, 2, 3, 4]
@allocation2 = stub :allocation2, :count => 3 #, ids: [5, 6, 7]
@allocation3 = stub :allocation3, :count => 2 #, ids: [8, 9]
@allocations = described_class.new [@allocation1, @allocation2, @allocation3]
end
describe 'lazy evaluation' do
context 'small amount' do
before(:each) do
@amount = 3
@amount = 5
@offset = 1
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(3,1).and_return [1, 2, 3]
@allocation2.should_receive(:process!).once.with(0,0).and_return [] # TODO Actually ok?
@allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
@allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 0
Expand All @@ -107,12 +107,103 @@
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(1,0).and_return [1]
@allocation2.should_receive(:process!).once.with(0,0).and_return [] # TODO Actually ok?
@allocation2.should_receive(:process!).never
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 0
end
end
context 'small amount and early 1' do
before(:each) do
@amount = 5
@offset = 1
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
@allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 1
end
end
context 'larger amount and early 1' do
before(:each) do
@amount = 1
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(1,0).and_return [1]
@allocation2.should_receive(:process!).once.with(0,0).and_return []
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 1
end
end
context 'larger amount and early 0' do
before(:each) do
@amount = 4
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
@allocation2.should_receive(:process!).never
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 0
end
end
context 'larger amount and early 1' do
before(:each) do
@amount = 4
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
@allocation2.should_receive(:process!).once.with(0,0).and_return []
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 1
end
end
context 'larger amount and early 0' do
before(:each) do
@amount = 5
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
@allocation2.should_receive(:process!).once.with(1,0).and_return [5]
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 0
end
end
context 'larger amount and early 1' do
before(:each) do
@amount = 5
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
@allocation2.should_receive(:process!).once.with(1,0).and_return [5]
@allocation3.should_receive(:process!).never

@allocations.process! @amount, @offset, 1
end
end
context 'larger amount and early 1' do
before(:each) do
@amount = 8
@offset = 0
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(8,0).and_return [1, 2, 3, 4]
@allocation2.should_receive(:process!).once.with(4,0).and_return [5, 6, 7]
@allocation3.should_receive(:process!).once.with(1,0).and_return [8]

@allocations.process! @amount, @offset, 1
end
end
end
describe 'amount spanning 3 allocations' do
before(:each) do
Expand Down Expand Up @@ -162,7 +253,8 @@
end
it 'should return certain ids' do
@allocation1.should_receive(:process!).once.with(3,0).and_return [1,2,3]
@allocation2.should_receive(:process!).once.with(0,0)
@allocation2.should_receive(:process!).once.with(0,0).and_return []
@allocation3.should_receive(:process!).once.with(0,0).and_return []

@allocations.process! @amount, @offset
end
Expand All @@ -174,6 +266,7 @@
it 'should return certain ids' do
@allocation1.should_receive(:process!).once.with(3,3).and_return [4]
@allocation2.should_receive(:process!).once.with(2,0).and_return [5,6]
@allocation3.should_receive(:process!).once.with(0,0).and_return []

@allocations.process! @amount, @offset
end
Expand Down
2 changes: 1 addition & 1 deletion version.rb
@@ -1,3 +1,3 @@
module Picky
VERSION = '3.6.13'
VERSION = '3.6.14'
end

0 comments on commit 2e628bd

Please sign in to comment.