diff --git a/src/collector/top_score_collector.rs b/src/collector/top_score_collector.rs index 6eeb287ac..ef302c795 100644 --- a/src/collector/top_score_collector.rs +++ b/src/collector/top_score_collector.rs @@ -519,7 +519,7 @@ impl Collector for TopDocs { })?; } - let fruit = heap + let fruit: Vec<(Score, DocAddress)> = heap .into_sorted_vec() .into_iter() .map(|cid| (cid.feature, DocAddress(segment_ord, cid.doc))) diff --git a/src/postings/skip.rs b/src/postings/skip.rs index 82b96f4dc..46097777c 100644 --- a/src/postings/skip.rs +++ b/src/postings/skip.rs @@ -103,7 +103,7 @@ impl SkipReader { } pub fn block_max_score(&self) -> Score { - unimplemented!(); + f32::MAX } pub(crate) fn last_doc_in_block(&self) -> DocId { diff --git a/src/query/boolean_query/block_wand.rs b/src/query/boolean_query/block_wand.rs index 3b5fb74bc..9df5c7bf7 100644 --- a/src/query/boolean_query/block_wand.rs +++ b/src/query/boolean_query/block_wand.rs @@ -46,14 +46,16 @@ fn compute_score(scorers: &mut Vec, doc: DocId) -> Score { score } -fn advance_all_scorers(scorers: &mut Vec) { +fn advance_all_scorers(scorers: &mut Vec, pivot: DocId) { let mut i = 0; while i < scorers.len() { - if scorers[i].advance() == TERMINATED { - scorers.swap_remove(i); - } else { - i += 1; + if scorers[i].doc() == pivot { + if scorers[i].advance() == TERMINATED { + scorers.swap_remove(i); + continue; + } } + i += 1; } } @@ -92,13 +94,12 @@ pub fn block_wand( continue; } } - // TODO no need to fully score? let score = compute_score(&mut scorers, pivot_doc); if score > threshold { threshold = callback(pivot_doc, score); } - advance_all_scorers(&mut scorers); + advance_all_scorers(&mut scorers, pivot_doc); } else { return; } diff --git a/src/query/boolean_query/boolean_weight.rs b/src/query/boolean_query/boolean_weight.rs index f320f9858..7f75f3983 100644 --- a/src/query/boolean_query/boolean_weight.rs +++ b/src/query/boolean_query/boolean_weight.rs @@ -10,16 +10,16 @@ use crate::query::RequiredOptionalScorer; use crate::query::Scorer; use crate::query::Weight; use crate::query::{intersect_scorers, Explanation}; -use crate::query::{TermUnion, Union}; +use crate::query::Union; use crate::{DocId, Score}; use std::collections::HashMap; -enum SpecializedScorer { - TermUnion(Union), +enum SpecializedScorer { + TermUnion(Vec), Other(Box), } -fn scorer_union(scorers: Vec>) -> SpecializedScorer +fn scorer_union(scorers: Vec>) -> SpecializedScorer where TScoreCombiner: ScoreCombiner, { @@ -35,21 +35,20 @@ where .into_iter() .map(|scorer| *(scorer.downcast::().map_err(|_| ()).unwrap())) .collect(); - return SpecializedScorer::TermUnion(Union::::from( - scorers, - )); + return SpecializedScorer::TermUnion(scorers); } } SpecializedScorer::Other(Box::new(Union::<_, TScoreCombiner>::from(scorers))) } -impl Into> for SpecializedScorer { - fn into(self) -> Box { - match self { - Self::TermUnion(union) => Box::new(union), - Self::Other(scorer) => scorer, +fn into_box_scorer(scorer: SpecializedScorer) -> Box { + match scorer { + SpecializedScorer::TermUnion(term_scorers) => { + let union_scorer = Union::::from(term_scorers); + Box::new(union_scorer) + }, + SpecializedScorer::Other(scorer) => scorer, } - } } pub struct BooleanWeight { @@ -85,23 +84,23 @@ impl BooleanWeight { &self, reader: &SegmentReader, boost: f32, - ) -> crate::Result> { + ) -> crate::Result { let mut per_occur_scorers = self.per_occur_scorers(reader, boost)?; - let should_scorer_opt: Option> = per_occur_scorers + let should_scorer_opt: Option = per_occur_scorers .remove(&Occur::Should) .map(scorer_union::); let exclude_scorer_opt: Option> = per_occur_scorers .remove(&Occur::MustNot) .map(scorer_union::) - .map(Into::into); + .map(|specialized_scorer| into_box_scorer::(specialized_scorer)); let must_scorer_opt: Option> = per_occur_scorers .remove(&Occur::Must) .map(intersect_scorers); - let positive_scorer: SpecializedScorer = + let positive_scorer: SpecializedScorer = match (should_scorer_opt, must_scorer_opt) { (Some(should_scorer), Some(must_scorer)) => { if self.scoring_enabled { @@ -110,7 +109,7 @@ impl BooleanWeight { Box, TScoreCombiner, >::new( - must_scorer, should_scorer.into() + must_scorer, into_box_scorer::(should_scorer) ))) } else { SpecializedScorer::Other(must_scorer) @@ -124,7 +123,7 @@ impl BooleanWeight { }; if let Some(exclude_scorer) = exclude_scorer_opt { - let positive_scorer_boxed: Box = positive_scorer.into(); + let positive_scorer_boxed: Box = into_box_scorer::(positive_scorer); Ok(SpecializedScorer::Other(Box::new(Exclude::new( positive_scorer_boxed, exclude_scorer, @@ -148,10 +147,10 @@ impl Weight for BooleanWeight { } } else if self.scoring_enabled { self.complex_scorer::(reader, boost) - .map(Into::into) + .map(|specialized_scorer| into_box_scorer::(specialized_scorer)) } else { self.complex_scorer::(reader, boost) - .map(Into::into) + .map(into_box_scorer::) } } @@ -182,7 +181,8 @@ impl Weight for BooleanWeight { ) -> crate::Result<()> { let scorer = self.complex_scorer::(reader, 1.0f32)?; match scorer { - SpecializedScorer::TermUnion(mut union_scorer) => { + SpecializedScorer::TermUnion(term_scorers) => { + let mut union_scorer = Union::::from(term_scorers); for_each_scorer(&mut union_scorer, callback); } SpecializedScorer::Other(mut scorer) => { @@ -210,8 +210,8 @@ impl Weight for BooleanWeight { ) -> crate::Result<()> { let scorer = self.complex_scorer::(reader, 1.0f32)?; match scorer { - SpecializedScorer::TermUnion(mut union_scorer) => { - for_each_pruning_scorer(&mut union_scorer, threshold, callback); + SpecializedScorer::TermUnion(term_scorers) => { + super::block_wand(term_scorers, threshold, callback); } SpecializedScorer::Other(mut scorer) => { for_each_pruning_scorer(scorer.as_mut(), threshold, callback); diff --git a/src/query/mod.rs b/src/query/mod.rs index 8a40f4604..d07e46cb6 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -27,7 +27,7 @@ mod vec_docset; pub(crate) mod score_combiner; pub use self::intersection::Intersection; -pub use self::union::{TermUnion, Union}; +pub use self::union::Union; #[cfg(test)] pub use self::vec_docset::VecDocSet; diff --git a/src/query/term_query/term_scorer.rs b/src/query/term_query/term_scorer.rs index bd2391918..b98e82e58 100644 --- a/src/query/term_query/term_scorer.rs +++ b/src/query/term_query/term_scorer.rs @@ -48,7 +48,7 @@ impl TermScorer { } pub fn max_score(&self) -> f32 { - unimplemented!(); + f32::MAX } } diff --git a/src/query/union.rs b/src/query/union.rs index 17f477da1..fed667b23 100644 --- a/src/query/union.rs +++ b/src/query/union.rs @@ -1,9 +1,6 @@ use crate::common::TinySet; use crate::docset::{DocSet, TERMINATED}; -use crate::fastfield::DeleteBitSet; -use crate::query::boolean_query::block_wand; use crate::query::score_combiner::{DoNothingCombiner, ScoreCombiner}; -use crate::query::term_query::TermScorer; use crate::query::Scorer; use crate::DocId; use crate::Score; @@ -246,55 +243,6 @@ where } } -pub struct TermUnion { - underlying: Union, -} - -impl From> for TermUnion { - fn from(scorers: Vec) -> Self { - TermUnion { - underlying: Union::from(scorers), - } - } -} - -impl DocSet for TermUnion { - fn advance(&mut self) -> u32 { - self.underlying.advance() - } - - fn seek(&mut self, target: u32) -> u32 { - self.underlying.seek(target) - } - - fn fill_buffer(&mut self, buffer: &mut [u32]) -> usize { - self.underlying.fill_buffer(buffer) - } - - fn doc(&self) -> u32 { - self.underlying.doc() - } - - fn size_hint(&self) -> u32 { - self.underlying.size_hint() - } - - fn count(&mut self, delete_bitset: &DeleteBitSet) -> u32 { - self.underlying.count(delete_bitset) - } - - fn count_including_deleted(&mut self) -> u32 { - self.underlying.count_including_deleted() - } -} - -impl Scorer for TermUnion { - fn score(&mut self) -> f32 { - self.underlying.score() - } - -} - #[cfg(test)] mod tests {