From 6c8c90d348214c7acfa24dfa0de17317d2f9a75b Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Sun, 18 Feb 2018 09:10:45 +0900 Subject: [PATCH] Removed lifetime from scorer --- src/postings/intersection.rs | 4 ---- src/query/all_query.rs | 2 +- src/query/boolean_query/boolean_weight.rs | 22 +++++++++++----------- src/query/exclude.rs | 2 +- src/query/phrase_query/phrase_weight.rs | 2 +- src/query/range_query.rs | 2 +- src/query/score_combiner.rs | 2 +- src/query/scorer.rs | 4 ++-- src/query/term_query/term_weight.rs | 2 +- src/query/weight.rs | 2 +- 10 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/postings/intersection.rs b/src/postings/intersection.rs index 74b636f8e..306edb127 100644 --- a/src/postings/intersection.rs +++ b/src/postings/intersection.rs @@ -75,10 +75,6 @@ impl DocSet for Intersection { fn skip_next(&mut self, target: DocId) -> SkipResult { // We optimize skipping by skipping every single member // of the intersection to target. - - // TODO fix BUG... - // what if we overstep on the second member of the intersection? - // The first member is not necessarily correct. let mut current_target: DocId = target; let mut current_ord = self.docsets.len(); diff --git a/src/query/all_query.rs b/src/query/all_query.rs index 226a3689f..b96c3258c 100644 --- a/src/query/all_query.rs +++ b/src/query/all_query.rs @@ -29,7 +29,7 @@ impl Query for AllQuery { pub struct AllWeight; impl Weight for AllWeight { - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { + fn scorer(&self, reader: &SegmentReader) -> Result> { Ok(box AllScorer { started: false, doc: 0u32, diff --git a/src/query/boolean_query/boolean_weight.rs b/src/query/boolean_query/boolean_weight.rs index 3f97c4f7e..5f71d024f 100644 --- a/src/query/boolean_query/boolean_weight.rs +++ b/src/query/boolean_query/boolean_weight.rs @@ -35,26 +35,26 @@ impl BooleanWeight { } } - fn complex_scorer<'a, TScoreCombiner: ScoreCombiner + 'static>( - &'a self, - reader: &'a SegmentReader, - ) -> Result> { - let mut per_occur_scorers: HashMap>> = HashMap::new(); + fn complex_scorer( + &self, + reader: &SegmentReader, + ) -> Result> { + let mut per_occur_scorers: HashMap>> = HashMap::new(); for &(ref occur, ref subweight) in self.weights.iter() { - let sub_scorer: Box = subweight.scorer(reader)?; + let sub_scorer: Box = subweight.scorer(reader)?; per_occur_scorers .entry(*occur) .or_insert_with(Vec::new) .push(sub_scorer); } - let should_scorer_opt: Option> = + let should_scorer_opt: Option> = per_occur_scorers.remove(&Occur::Should).map(scorer_union::); - let exclude_scorer_opt: Option> = + let exclude_scorer_opt: Option> = per_occur_scorers.remove(&Occur::MustNot).map(scorer_union::); - let must_scorer_opt: Option> = + let must_scorer_opt: Option> = per_occur_scorers.remove(&Occur::Must).map(|scorers| { if scorers.len() == 1 { scorers.into_iter().next().unwrap() @@ -64,7 +64,7 @@ impl BooleanWeight { } }); - let positive_scorer: Box = match (should_scorer_opt, must_scorer_opt) { + let positive_scorer: Box = match (should_scorer_opt, must_scorer_opt) { (Some(should_scorer), Some(must_scorer)) => { if self.scoring_enabled { box RequiredOptionalScorer::<_,_,TScoreCombiner>::new(must_scorer, should_scorer) @@ -88,7 +88,7 @@ impl BooleanWeight { } impl Weight for BooleanWeight { - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { + fn scorer(&self, reader: &SegmentReader) -> Result> { if self.weights.is_empty() { Ok(box EmptyScorer) } else if self.weights.len() == 1 { diff --git a/src/query/exclude.rs b/src/query/exclude.rs index c82d0e252..2c99645ef 100644 --- a/src/query/exclude.rs +++ b/src/query/exclude.rs @@ -120,7 +120,7 @@ where impl Scorer for Exclude where TScorer: Scorer, - TDocSetExclude: DocSet, + TDocSetExclude: DocSet + 'static { fn score(&mut self) -> Score { self.underlying_docset.score() diff --git a/src/query/phrase_query/phrase_weight.rs b/src/query/phrase_query/phrase_weight.rs index 6bef26f75..70571dc57 100644 --- a/src/query/phrase_query/phrase_weight.rs +++ b/src/query/phrase_query/phrase_weight.rs @@ -22,7 +22,7 @@ impl PhraseWeight { } impl Weight for PhraseWeight { - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { + fn scorer(&self, reader: &SegmentReader) -> Result> { let mut term_postings_list = Vec::new(); for term in &self.phrase_terms { if let Some(postings) = reader diff --git a/src/query/range_query.rs b/src/query/range_query.rs index d9192ebc7..5f2284521 100644 --- a/src/query/range_query.rs +++ b/src/query/range_query.rs @@ -170,7 +170,7 @@ impl RangeWeight { } impl Weight for RangeWeight { - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { + fn scorer(&self, reader: &SegmentReader) -> Result> { let max_doc = reader.max_doc(); let mut doc_bitset = BitSet::with_max_value(max_doc); diff --git a/src/query/score_combiner.rs b/src/query/score_combiner.rs index 50bc85b9f..dd6ec1864 100644 --- a/src/query/score_combiner.rs +++ b/src/query/score_combiner.rs @@ -4,7 +4,7 @@ use query::Scorer; /// The `ScoreCombiner` trait defines how to compute /// an overall score given a list of scores. -pub trait ScoreCombiner: Default + Clone + Copy { +pub trait ScoreCombiner: Default + Clone + Copy + 'static { /// Aggregates the score combiner with the given scorer. /// /// The `ScoreCombiner` may decide to call `.scorer.score()` diff --git a/src/query/scorer.rs b/src/query/scorer.rs index b76b6187d..cbe04db38 100644 --- a/src/query/scorer.rs +++ b/src/query/scorer.rs @@ -9,7 +9,7 @@ use std::ops::DerefMut; /// Scored set of documents matching a query within a specific segment. /// /// See [`Query`](./trait.Query.html). -pub trait Scorer: DocSet { +pub trait Scorer: DocSet + 'static { /// Returns the score. /// /// This method will perform a bit of computation and is not cached. @@ -112,7 +112,7 @@ impl DocSet for ConstScorer { } } -impl Scorer for ConstScorer { +impl Scorer for ConstScorer { fn score(&mut self) -> Score { 1f32 } diff --git a/src/query/term_query/term_weight.rs b/src/query/term_query/term_weight.rs index e330174b6..f8518f78d 100644 --- a/src/query/term_query/term_weight.rs +++ b/src/query/term_query/term_weight.rs @@ -16,7 +16,7 @@ pub struct TermWeight { } impl Weight for TermWeight { - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { + fn scorer(&self, reader: &SegmentReader) -> Result> { let specialized_scorer = self.specialized_scorer(reader)?; Ok(box specialized_scorer) } diff --git a/src/query/weight.rs b/src/query/weight.rs index 5e73f7311..44a4860e2 100644 --- a/src/query/weight.rs +++ b/src/query/weight.rs @@ -9,7 +9,7 @@ use core::SegmentReader; pub trait Weight { /// Returns the scorer for the given segment. /// See [`Query`](./trait.Query.html). - fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result>; + fn scorer(&self, reader: &SegmentReader) -> Result>; /// Returns the number documents within the given `SegmentReader`. fn count(&self, reader: &SegmentReader) -> Result {