Skip to content
This repository
Browse code

+ 3.6.14, ! terminate_early

  • Loading branch information...
commit 2e628bd0a5481ab0758a79b44c6f5cd9f01a8bcb 1 parent 6af3b12
Florian R. Hanke authored December 01, 2011
4  history.textile
Source Rendered
... ...
@@ -1,5 +1,9 @@
1 1
 h2. Upcoming Version
2 2
 
  3
+h2. Version 3.6.14
  4
+
  5
+* hanke: (server) Fix for terminate_early with offsets in 3.6.12 (thanks niko!).
  6
+
3 7
 h2. Version 3.6.13
4 8
 
5 9
 * hanke: (server) Fix for exact first matching (thanks geelen!).
3  server/lib/picky/query/allocations.rb
@@ -72,7 +72,6 @@ def ids amount = 20
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 @@ def process! amount, offset = 0, terminate_early = nil
82 81
             offset = 0                 # we have already passed the offset
83 82
           end
84 83
           if terminate_early
85  
-            break if terminate_early < 0 && offset <= 0
  84
+            break if terminate_early <= 0 && amount <= 0
86 85
             terminate_early -= 1
87 86
           end
88 87
         end
19  server/spec/functional/terminate_early_spec.rb
@@ -23,6 +23,9 @@
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 @@
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
109  server/spec/lib/query/allocations_spec.rb
@@ -81,20 +81,20 @@
81 81
 
82 82
   describe 'process!' do
83 83
     before(:each) do
84  
-      @allocation1 = stub :allocation1, :process! => [], :count => 4 #, ids: [1, 2, 3, 4]
85  
-      @allocation2 = stub :allocation2, :process! => [], :count => 3 #, ids: [5, 6, 7]
86  
-      @allocation3 = stub :allocation3, :process! => [], :count => 2 #, ids: [8, 9]
  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 = 3
  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(3,1).and_return [1, 2, 3]
97  
-          @allocation2.should_receive(:process!).once.with(0,0).and_return [] # TODO Actually ok?
  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 @@
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!).once.with(0,0).and_return [] # TODO Actually ok?
  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 @@
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 @@
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
2  version.rb
... ...
@@ -1,3 +1,3 @@
1 1
 module Picky
2  
-  VERSION = '3.6.13'
  2
+  VERSION = '3.6.14'
3 3
 end

0 notes on commit 2e628bd

Please sign in to comment.
Something went wrong with that request. Please try again.