Disable scoring

- Disabling scoring is an argument of the `.weight()` method
- Collectors declare whether they need scoring
This commit is contained in:
Paul Masurel
2018-02-17 12:43:16 +09:00
parent 0300e7272b
commit 292bb17346
17 changed files with 90 additions and 54 deletions
+4 -13
View File
@@ -22,14 +22,12 @@ use query::Occur;
#[derive(Debug)]
pub struct BooleanQuery {
subqueries: Vec<(Occur, Box<Query>)>,
scoring_disabled: bool,
}
impl From<Vec<(Occur, Box<Query>)>> for BooleanQuery {
fn from(subqueries: Vec<(Occur, Box<Query>)>) -> BooleanQuery {
BooleanQuery {
subqueries,
scoring_disabled: false,
subqueries
}
}
}
@@ -39,19 +37,12 @@ impl Query for BooleanQuery {
self
}
fn disable_scoring(&mut self) {
self.scoring_disabled = true;
for &mut (_, ref mut subquery) in &mut self.subqueries {
subquery.disable_scoring();
}
}
fn weight(&self, searcher: &Searcher) -> Result<Box<Weight>> {
fn weight(&self, searcher: &Searcher, scoring_enabled: bool) -> Result<Box<Weight>> {
let sub_weights = self.subqueries
.iter()
.map(|&(ref occur, ref subquery)| Ok((*occur, subquery.weight(searcher)?)))
.map(|&(ref occur, ref subquery)| Ok((*occur, subquery.weight(searcher, scoring_enabled)?)))
.collect::<Result<_>>()?;
Ok(box BooleanWeight::new(sub_weights, self.scoring_disabled))
Ok(box BooleanWeight::new(sub_weights, scoring_enabled))
}
}
+9 -10
View File
@@ -5,7 +5,6 @@ use std::collections::HashMap;
use query::EmptyScorer;
use query::Scorer;
use query::Exclude;
use query::ConstScorer;
use query::Occur;
use query::RequiredOptionalScorer;
use query::score_combiner::{SumWithCoordsCombiner, DoNothingCombiner, ScoreCombiner};
@@ -25,14 +24,14 @@ fn scorer_union<'a, TScoreCombiner>(docsets: Vec<Box<Scorer + 'a>>) -> Box<Score
pub struct BooleanWeight {
weights: Vec<(Occur, Box<Weight>)>,
scoring_disabled: bool,
scoring_enabled: bool,
}
impl BooleanWeight {
pub fn new(weights: Vec<(Occur, Box<Weight>)>, scoring_disabled: bool) -> BooleanWeight {
pub fn new(weights: Vec<(Occur, Box<Weight>)>, scoring_enabled: bool) -> BooleanWeight {
BooleanWeight {
weights,
scoring_disabled,
scoring_enabled,
}
}
@@ -67,10 +66,10 @@ impl BooleanWeight {
let positive_scorer: Box<Scorer> = match (should_scorer_opt, must_scorer_opt) {
(Some(should_scorer), Some(must_scorer)) => {
if self.scoring_disabled {
must_scorer
} else {
if self.scoring_enabled {
box RequiredOptionalScorer::<_,_,TScoreCombiner>::new(must_scorer, should_scorer)
} else {
must_scorer
}
}
(None, Some(must_scorer)) => must_scorer,
@@ -99,10 +98,10 @@ impl Weight for BooleanWeight {
} else {
weight.scorer(reader)
}
} else if self.scoring_disabled {
self.complex_scorer::<DoNothingCombiner>(reader)
} else {
} else if self.scoring_enabled {
self.complex_scorer::<SumWithCoordsCombiner>(reader)
} else {
self.complex_scorer::<DoNothingCombiner>(reader)
}
}
}