mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-14 21:12:54 +00:00
add collect_block to BoxableSegmentCollector (#2331)
This commit is contained in:
@@ -52,10 +52,16 @@ impl<TCollector: Collector> Collector for CollectorWrapper<TCollector> {
|
||||
impl SegmentCollector for Box<dyn BoxableSegmentCollector> {
|
||||
type Fruit = Box<dyn Fruit>;
|
||||
|
||||
#[inline]
|
||||
fn collect(&mut self, doc: u32, score: Score) {
|
||||
self.as_mut().collect(doc, score);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn collect_block(&mut self, docs: &[DocId]) {
|
||||
self.as_mut().collect_block(docs);
|
||||
}
|
||||
|
||||
fn harvest(self) -> Box<dyn Fruit> {
|
||||
BoxableSegmentCollector::harvest_from_box(self)
|
||||
}
|
||||
@@ -63,6 +69,11 @@ impl SegmentCollector for Box<dyn BoxableSegmentCollector> {
|
||||
|
||||
pub trait BoxableSegmentCollector {
|
||||
fn collect(&mut self, doc: u32, score: Score);
|
||||
fn collect_block(&mut self, docs: &[DocId]) {
|
||||
for &doc in docs {
|
||||
self.collect(doc, 0.0);
|
||||
}
|
||||
}
|
||||
fn harvest_from_box(self: Box<Self>) -> Box<dyn Fruit>;
|
||||
}
|
||||
|
||||
@@ -71,9 +82,14 @@ pub struct SegmentCollectorWrapper<TSegmentCollector: SegmentCollector>(TSegment
|
||||
impl<TSegmentCollector: SegmentCollector> BoxableSegmentCollector
|
||||
for SegmentCollectorWrapper<TSegmentCollector>
|
||||
{
|
||||
#[inline]
|
||||
fn collect(&mut self, doc: u32, score: Score) {
|
||||
self.0.collect(doc, score);
|
||||
}
|
||||
#[inline]
|
||||
fn collect_block(&mut self, docs: &[DocId]) {
|
||||
self.0.collect_block(docs);
|
||||
}
|
||||
|
||||
fn harvest_from_box(self: Box<Self>) -> Box<dyn Fruit> {
|
||||
Box::new(self.0.harvest())
|
||||
|
||||
Reference in New Issue
Block a user