mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-08-12 09:19:39 +00:00
Disable scoring
- Disabling scoring is an argument of the `.weight()` method - Collectors declare whether they need scoring
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user