From 2267722d01c82b3da630dd79682a20746cff96ac Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 13 Dec 2018 08:58:00 +0900 Subject: [PATCH] Added SegmentFruit --- examples/custom_collector.rs | 2 ++ src/collector/count_collector.rs | 1 + src/collector/facet_collector.rs | 2 ++ src/collector/mod.rs | 17 ++++++++++++----- src/collector/multi_collector.rs | 9 ++++++--- src/collector/tests.rs | 4 ++++ src/collector/top_field_collector.rs | 1 + src/collector/top_score_collector.rs | 1 + src/core/searcher.rs | 2 +- 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/examples/custom_collector.rs b/examples/custom_collector.rs index 0d19a83e5..5e28edb81 100644 --- a/examples/custom_collector.rs +++ b/examples/custom_collector.rs @@ -70,6 +70,8 @@ impl Collector for StatsCollector { // Our standard deviation will be a float. type Fruit = Option; + type SegmentFruit = Self::Fruit; + type Child = StatsSegmentCollector; fn for_segment( diff --git a/src/collector/count_collector.rs b/src/collector/count_collector.rs index ea2a1d9cd..14c75926b 100644 --- a/src/collector/count_collector.rs +++ b/src/collector/count_collector.rs @@ -58,6 +58,7 @@ pub struct Count; impl Collector for Count { type Fruit = usize; + type SegmentFruit = usize; type Child = SegmentCountCollector; diff --git a/src/collector/facet_collector.rs b/src/collector/facet_collector.rs index df2b7684c..7b625369c 100644 --- a/src/collector/facet_collector.rs +++ b/src/collector/facet_collector.rs @@ -258,6 +258,8 @@ impl FacetCollector { impl Collector for FacetCollector { type Fruit = FacetCounts; + type SegmentFruit = FacetCounts; + type Child = FacetSegmentCollector; fn for_segment( diff --git a/src/collector/mod.rs b/src/collector/mod.rs index 776b8a51b..86ee07f6e 100644 --- a/src/collector/mod.rs +++ b/src/collector/mod.rs @@ -136,8 +136,10 @@ pub trait Collector: Sync { /// e.g. `usize` for the `Count` collector. type Fruit: Fruit; + type SegmentFruit: Fruit; + /// Type of the `SegmentCollector` associated to this collector. - type Child: SegmentCollector; + type Child: SegmentCollector; /// `set_segment` is called before beginning to enumerate /// on this segment. @@ -152,7 +154,7 @@ pub trait Collector: Sync { /// Combines the fruit associated to the collection of each segments /// into one fruit. - fn merge_fruits(&self, segment_fruits: Vec) -> Result; + fn merge_fruits(&self, segment_fruits: Vec) -> Result; } /// The `SegmentCollector` is the trait in charge of defining the @@ -181,6 +183,9 @@ where Right: Collector, { type Fruit = (Left::Fruit, Right::Fruit); + + type SegmentFruit = (Left::SegmentFruit, Right::SegmentFruit); + type Child = (Left::Child, Right::Child); fn for_segment(&self, segment_local_id: u32, segment: &SegmentReader) -> Result { @@ -195,7 +200,7 @@ where fn merge_fruits( &self, - children: Vec<(Left::Fruit, Right::Fruit)>, + children: Vec<(Left::SegmentFruit, Right::SegmentFruit)>, ) -> Result<(Left::Fruit, Right::Fruit)> { let mut left_fruits = vec![]; let mut right_fruits = vec![]; @@ -236,6 +241,7 @@ where Three: Collector, { type Fruit = (One::Fruit, Two::Fruit, Three::Fruit); + type SegmentFruit = (One::SegmentFruit, Two::SegmentFruit, Three::SegmentFruit); type Child = (One::Child, Two::Child, Three::Child); fn for_segment(&self, segment_local_id: u32, segment: &SegmentReader) -> Result { @@ -249,7 +255,7 @@ where self.0.requires_scoring() || self.1.requires_scoring() || self.2.requires_scoring() } - fn merge_fruits(&self, children: Vec) -> Result { + fn merge_fruits(&self, children: Vec) -> Result { let mut one_fruits = vec![]; let mut two_fruits = vec![]; let mut three_fruits = vec![]; @@ -295,6 +301,7 @@ where Four: Collector, { type Fruit = (One::Fruit, Two::Fruit, Three::Fruit, Four::Fruit); + type SegmentFruit = (One::SegmentFruit, Two::SegmentFruit, Three::SegmentFruit, Four::SegmentFruit); type Child = (One::Child, Two::Child, Three::Child, Four::Child); fn for_segment(&self, segment_local_id: u32, segment: &SegmentReader) -> Result { @@ -312,7 +319,7 @@ where || self.3.requires_scoring() } - fn merge_fruits(&self, children: Vec) -> Result { + fn merge_fruits(&self, children: Vec) -> Result { let mut one_fruits = vec![]; let mut two_fruits = vec![]; let mut three_fruits = vec![]; diff --git a/src/collector/multi_collector.rs b/src/collector/multi_collector.rs index 2595e7f24..11814e1c6 100644 --- a/src/collector/multi_collector.rs +++ b/src/collector/multi_collector.rs @@ -18,6 +18,7 @@ pub struct CollectorWrapper(TCollector); impl Collector for CollectorWrapper { type Fruit = Box; + type SegmentFruit = Box; type Child = Box; fn for_segment( @@ -34,10 +35,10 @@ impl Collector for CollectorWrapper { } fn merge_fruits(&self, children: Vec<::Fruit>) -> Result> { - let typed_fruit: Vec = children + let typed_fruit: Vec = children .into_iter() .map(|untyped_fruit| { - Downcast::::downcast(untyped_fruit) + Downcast::::downcast(untyped_fruit) .map(|boxed_but_typed| *boxed_but_typed) .map_err(|e| { let err_msg = format!("Failed to cast child collector fruit. {:?}", e); @@ -152,7 +153,7 @@ impl FruitHandle { #[derive(Default)] pub struct MultiCollector<'a> { collector_wrappers: - Vec, Fruit = Box> + 'a>>, + Vec, Fruit = Box, SegmentFruit = Box> + 'a>>, } impl<'a> MultiCollector<'a> { @@ -177,7 +178,9 @@ impl<'a> MultiCollector<'a> { } impl<'a> Collector for MultiCollector<'a> { + type Fruit = MultiFruit; + type SegmentFruit = MultiFruit; type Child = MultiCollectorChild; fn for_segment( diff --git a/src/collector/tests.rs b/src/collector/tests.rs index cc8bcfff4..421f505a3 100644 --- a/src/collector/tests.rs +++ b/src/collector/tests.rs @@ -40,6 +40,7 @@ impl TestFruit { impl Collector for TestCollector { type Fruit = TestFruit; + type SegmentFruit = Self::Fruit; type Child = TestSegmentCollector; fn for_segment( @@ -109,6 +110,8 @@ impl FastFieldTestCollector { impl Collector for FastFieldTestCollector { type Fruit = Vec; + type SegmentFruit = Self::Fruit; + type Child = FastFieldSegmentCollector; fn for_segment( @@ -165,6 +168,7 @@ impl BytesFastFieldTestCollector { impl Collector for BytesFastFieldTestCollector { type Fruit = Vec; + type SegmentFruit = Self::Fruit; type Child = BytesFastFieldSegmentCollector; fn for_segment( diff --git a/src/collector/top_field_collector.rs b/src/collector/top_field_collector.rs index c6c5c29a7..8e2b3a43c 100644 --- a/src/collector/top_field_collector.rs +++ b/src/collector/top_field_collector.rs @@ -88,6 +88,7 @@ impl TopDocsByField { impl Collector for TopDocsByField { type Fruit = Vec<(T, DocAddress)>; + type SegmentFruit = Vec<(T, DocAddress)>; type Child = TopFieldSegmentCollector; diff --git a/src/collector/top_score_collector.rs b/src/collector/top_score_collector.rs index 2ba5ffc87..ba8235db2 100644 --- a/src/collector/top_score_collector.rs +++ b/src/collector/top_score_collector.rs @@ -89,6 +89,7 @@ impl TopDocs { impl Collector for TopDocs { type Fruit = Vec<(Score, DocAddress)>; + type SegmentFruit = Vec<(Score, DocAddress)>; type Child = TopScoreSegmentCollector; diff --git a/src/core/searcher.rs b/src/core/searcher.rs index 9e74fddd0..53bc8fa23 100644 --- a/src/core/searcher.rs +++ b/src/core/searcher.rs @@ -23,7 +23,7 @@ fn collect_segment( weight: &Weight, segment_ord: u32, segment_reader: &SegmentReader, -) -> Result { +) -> Result { let mut scorer = weight.scorer(segment_reader)?; let mut segment_collector = collector.for_segment(segment_ord as u32, segment_reader)?; if let Some(delete_bitset) = segment_reader.delete_bitset() {