Skip to content

Commit 82f14d0

Browse files
stuhoodfulmicoton-dd
authored andcommitted
Implement collect_block for Collectors which wrap other Collectors (#2727)
* Implement `collect_block` for tuple Collectors, and for MultiCollector. * Two more.
1 parent 25c4fe6 commit 82f14d0

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/collector/filter_collector_wrapper.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ where
120120
segment_collector,
121121
predicate: self.predicate.clone(),
122122
t_predicate_value: PhantomData,
123+
filtered_docs: Vec::with_capacity(crate::COLLECT_BLOCK_BUFFER_LEN),
123124
})
124125
}
125126

@@ -140,6 +141,7 @@ pub struct FilterSegmentCollector<TSegmentCollector, TPredicate, TPredicateValue
140141
segment_collector: TSegmentCollector,
141142
predicate: TPredicate,
142143
t_predicate_value: PhantomData<TPredicateValue>,
144+
filtered_docs: Vec<DocId>,
143145
}
144146

145147
impl<TSegmentCollector, TPredicate, TPredicateValue>
@@ -176,6 +178,20 @@ where
176178
}
177179
}
178180

181+
fn collect_block(&mut self, docs: &[DocId]) {
182+
self.filtered_docs.clear();
183+
for &doc in docs {
184+
// TODO: `accept_document` could be further optimized to do batch lookups of column
185+
// values for single-valued columns.
186+
if self.accept_document(doc) {
187+
self.filtered_docs.push(doc);
188+
}
189+
}
190+
if !self.filtered_docs.is_empty() {
191+
self.segment_collector.collect_block(&self.filtered_docs);
192+
}
193+
}
194+
179195
fn harvest(self) -> TSegmentCollector::Fruit {
180196
self.segment_collector.harvest()
181197
}
@@ -274,6 +290,7 @@ where
274290
segment_collector,
275291
predicate: self.predicate.clone(),
276292
buffer: Vec::new(),
293+
filtered_docs: Vec::with_capacity(crate::COLLECT_BLOCK_BUFFER_LEN),
277294
})
278295
}
279296

@@ -296,6 +313,7 @@ where TPredicate: 'static
296313
segment_collector: TSegmentCollector,
297314
predicate: TPredicate,
298315
buffer: Vec<u8>,
316+
filtered_docs: Vec<DocId>,
299317
}
300318

301319
impl<TSegmentCollector, TPredicate> BytesFilterSegmentCollector<TSegmentCollector, TPredicate>
@@ -334,6 +352,20 @@ where
334352
}
335353
}
336354

355+
fn collect_block(&mut self, docs: &[DocId]) {
356+
self.filtered_docs.clear();
357+
for &doc in docs {
358+
// TODO: `accept_document` could be further optimized to do batch lookups of column
359+
// values for single-valued columns.
360+
if self.accept_document(doc) {
361+
self.filtered_docs.push(doc);
362+
}
363+
}
364+
if !self.filtered_docs.is_empty() {
365+
self.segment_collector.collect_block(&self.filtered_docs);
366+
}
367+
}
368+
337369
fn harvest(self) -> TSegmentCollector::Fruit {
338370
self.segment_collector.harvest()
339371
}

src/collector/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ impl<TSegmentCollector: SegmentCollector> SegmentCollector for Option<TSegmentCo
214214
}
215215
}
216216

217+
fn collect_block(&mut self, docs: &[DocId]) {
218+
if let Some(segment_collector) = self {
219+
segment_collector.collect_block(docs);
220+
}
221+
}
222+
217223
fn harvest(self) -> Self::Fruit {
218224
self.map(|segment_collector| segment_collector.harvest())
219225
}
@@ -342,6 +348,11 @@ where
342348
self.1.collect(doc, score);
343349
}
344350

351+
fn collect_block(&mut self, docs: &[DocId]) {
352+
self.0.collect_block(docs);
353+
self.1.collect_block(docs);
354+
}
355+
345356
fn harvest(self) -> <Self as SegmentCollector>::Fruit {
346357
(self.0.harvest(), self.1.harvest())
347358
}
@@ -407,6 +418,12 @@ where
407418
self.2.collect(doc, score);
408419
}
409420

421+
fn collect_block(&mut self, docs: &[DocId]) {
422+
self.0.collect_block(docs);
423+
self.1.collect_block(docs);
424+
self.2.collect_block(docs);
425+
}
426+
410427
fn harvest(self) -> <Self as SegmentCollector>::Fruit {
411428
(self.0.harvest(), self.1.harvest(), self.2.harvest())
412429
}
@@ -482,6 +499,13 @@ where
482499
self.3.collect(doc, score);
483500
}
484501

502+
fn collect_block(&mut self, docs: &[DocId]) {
503+
self.0.collect_block(docs);
504+
self.1.collect_block(docs);
505+
self.2.collect_block(docs);
506+
self.3.collect_block(docs);
507+
}
508+
485509
fn harvest(self) -> <Self as SegmentCollector>::Fruit {
486510
(
487511
self.0.harvest(),

src/collector/multi_collector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ impl SegmentCollector for MultiCollectorChild {
250250
}
251251
}
252252

253+
fn collect_block(&mut self, docs: &[DocId]) {
254+
for child in &mut self.children {
255+
child.collect_block(docs);
256+
}
257+
}
258+
253259
fn harvest(self) -> MultiFruit {
254260
MultiFruit {
255261
sub_fruits: self

0 commit comments

Comments
 (0)