@@ -172,19 +172,33 @@ pub trait Collector: Sync + Send {
172
172
) -> crate :: Result < <Self :: Child as SegmentCollector >:: Fruit > {
173
173
let mut segment_collector = self . for_segment ( segment_ord as u32 , reader) ?;
174
174
175
+ let mut cache_pos = 0 ;
176
+ let mut cache = [ ( 0 , 0.0 ) ; 64 ] ;
177
+
175
178
if let Some ( alive_bitset) = reader. alive_bitset ( ) {
176
179
weight. for_each ( reader, & mut |doc, score| {
177
180
if alive_bitset. is_alive ( doc) {
178
- segment_collector. collect ( doc, score) ?;
181
+ cache[ cache_pos] = ( doc, score) ;
182
+ cache_pos += 1 ;
183
+ if cache_pos == 64 {
184
+ segment_collector. collect_block ( & cache) ?;
185
+ cache_pos = 0 ;
186
+ }
179
187
}
180
188
Ok ( ( ) )
181
189
} ) ?;
182
190
} else {
183
191
weight. for_each ( reader, & mut |doc, score| {
184
- segment_collector. collect ( doc, score) ?;
192
+ cache[ cache_pos] = ( doc, score) ;
193
+ cache_pos += 1 ;
194
+ if cache_pos == 64 {
195
+ segment_collector. collect_block ( & cache) ?;
196
+ cache_pos = 0 ;
197
+ }
185
198
Ok ( ( ) )
186
199
} ) ?;
187
200
}
201
+ segment_collector. collect_block ( & cache[ ..cache_pos] ) ?;
188
202
Ok ( segment_collector. harvest ( ) )
189
203
}
190
204
}
@@ -258,6 +272,14 @@ pub trait SegmentCollector: 'static {
258
272
/// The query pushes the scored document to the collector via this method.
259
273
fn collect ( & mut self , doc : DocId , score : Score ) -> crate :: Result < ( ) > ;
260
274
275
+ /// The query pushes the scored document to the collector via this method.
276
+ fn collect_block ( & mut self , docs : & [ ( DocId , Score ) ] ) -> crate :: Result < ( ) > {
277
+ for ( doc, score) in docs {
278
+ self . collect ( * doc, * score) ?;
279
+ }
280
+ Ok ( ( ) )
281
+ }
282
+
261
283
/// Extract the fruit of the collection from the `SegmentCollector`.
262
284
fn harvest ( self ) -> Self :: Fruit ;
263
285
}
@@ -317,6 +339,12 @@ where
317
339
Ok ( ( ) )
318
340
}
319
341
342
+ fn collect_block ( & mut self , docs : & [ ( DocId , Score ) ] ) -> crate :: Result < ( ) > {
343
+ self . 0 . collect_block ( docs) ?;
344
+ self . 1 . collect_block ( docs) ?;
345
+ Ok ( ( ) )
346
+ }
347
+
320
348
fn harvest ( self ) -> <Self as SegmentCollector >:: Fruit {
321
349
( self . 0 . harvest ( ) , self . 1 . harvest ( ) )
322
350
}
@@ -383,6 +411,13 @@ where
383
411
Ok ( ( ) )
384
412
}
385
413
414
+ fn collect_block ( & mut self , docs : & [ ( DocId , Score ) ] ) -> crate :: Result < ( ) > {
415
+ self . 0 . collect_block ( docs) ?;
416
+ self . 1 . collect_block ( docs) ?;
417
+ self . 2 . collect_block ( docs) ?;
418
+ Ok ( ( ) )
419
+ }
420
+
386
421
fn harvest ( self ) -> <Self as SegmentCollector >:: Fruit {
387
422
( self . 0 . harvest ( ) , self . 1 . harvest ( ) , self . 2 . harvest ( ) )
388
423
}
@@ -459,6 +494,14 @@ where
459
494
Ok ( ( ) )
460
495
}
461
496
497
+ fn collect_block ( & mut self , docs : & [ ( DocId , Score ) ] ) -> crate :: Result < ( ) > {
498
+ self . 0 . collect_block ( docs) ?;
499
+ self . 1 . collect_block ( docs) ?;
500
+ self . 2 . collect_block ( docs) ?;
501
+ self . 3 . collect_block ( docs) ?;
502
+ Ok ( ( ) )
503
+ }
504
+
462
505
fn harvest ( self ) -> <Self as SegmentCollector >:: Fruit {
463
506
(
464
507
self . 0 . harvest ( ) ,
0 commit comments