Removed lifetime from scorer

This commit is contained in:
Paul Masurel
2018-02-18 09:10:45 +09:00
parent eb50e92ec4
commit 6c8c90d348
10 changed files with 20 additions and 24 deletions

View File

@@ -75,10 +75,6 @@ impl<TDocSet: DocSet> DocSet for Intersection<TDocSet> {
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();

View File

@@ -29,7 +29,7 @@ impl Query for AllQuery {
pub struct AllWeight;
impl Weight for AllWeight {
fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
Ok(box AllScorer {
started: false,
doc: 0u32,

View File

@@ -35,26 +35,26 @@ impl BooleanWeight {
}
}
fn complex_scorer<'a, TScoreCombiner: ScoreCombiner + 'static>(
&'a self,
reader: &'a SegmentReader,
) -> Result<Box<Scorer + 'a>> {
let mut per_occur_scorers: HashMap<Occur, Vec<Box<Scorer + 'a>>> = HashMap::new();
fn complex_scorer<TScoreCombiner: ScoreCombiner>(
&self,
reader: &SegmentReader,
) -> Result<Box<Scorer>> {
let mut per_occur_scorers: HashMap<Occur, Vec<Box<Scorer>>> = HashMap::new();
for &(ref occur, ref subweight) in self.weights.iter() {
let sub_scorer: Box<Scorer + 'a> = subweight.scorer(reader)?;
let sub_scorer: Box<Scorer> = subweight.scorer(reader)?;
per_occur_scorers
.entry(*occur)
.or_insert_with(Vec::new)
.push(sub_scorer);
}
let should_scorer_opt: Option<Box<Scorer + 'a>> =
let should_scorer_opt: Option<Box<Scorer>> =
per_occur_scorers.remove(&Occur::Should).map(scorer_union::<TScoreCombiner>);
let exclude_scorer_opt: Option<Box<Scorer + 'a>> =
let exclude_scorer_opt: Option<Box<Scorer>> =
per_occur_scorers.remove(&Occur::MustNot).map(scorer_union::<TScoreCombiner>);
let must_scorer_opt: Option<Box<Scorer + 'a>> =
let must_scorer_opt: Option<Box<Scorer>> =
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<Scorer> = match (should_scorer_opt, must_scorer_opt) {
let positive_scorer: Box<Scorer > = 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<Box<Scorer + 'a>> {
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
if self.weights.is_empty() {
Ok(box EmptyScorer)
} else if self.weights.len() == 1 {

View File

@@ -120,7 +120,7 @@ where
impl<TScorer, TDocSetExclude> Scorer for Exclude<TScorer, TDocSetExclude>
where
TScorer: Scorer,
TDocSetExclude: DocSet,
TDocSetExclude: DocSet + 'static
{
fn score(&mut self) -> Score {
self.underlying_docset.score()

View File

@@ -22,7 +22,7 @@ impl PhraseWeight {
}
impl Weight for PhraseWeight {
fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
let mut term_postings_list = Vec::new();
for term in &self.phrase_terms {
if let Some(postings) = reader

View File

@@ -170,7 +170,7 @@ impl RangeWeight {
}
impl Weight for RangeWeight {
fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
let max_doc = reader.max_doc();
let mut doc_bitset = BitSet::with_max_value(max_doc);

View File

@@ -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()`

View File

@@ -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<TDocSet: DocSet> DocSet for ConstScorer<TDocSet> {
}
}
impl<TDocSet: DocSet> Scorer for ConstScorer<TDocSet> {
impl<TDocSet: DocSet + 'static> Scorer for ConstScorer<TDocSet> {
fn score(&mut self) -> Score {
1f32
}

View File

@@ -16,7 +16,7 @@ pub struct TermWeight {
}
impl Weight for TermWeight {
fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
let specialized_scorer = self.specialized_scorer(reader)?;
Ok(box specialized_scorer)
}

View File

@@ -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<Box<Scorer + 'a>>;
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>>;
/// Returns the number documents within the given `SegmentReader`.
fn count(&self, reader: &SegmentReader) -> Result<u32> {