Added disabling scoring

This commit is contained in:
Paul Masurel
2018-02-02 12:11:56 +09:00
parent 63d201150b
commit dd8332c327
10 changed files with 39 additions and 18 deletions

View File

@@ -22,11 +22,15 @@ 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 }
BooleanQuery {
subqueries,
scoring_disabled: false
}
}
}
@@ -42,7 +46,11 @@ impl Query for BooleanQuery {
Ok((*occur, subquery.weight(searcher)?))
})
.collect::<Result<_>>()?;
Ok(box BooleanWeight::new(sub_weights))
Ok(box BooleanWeight::new(sub_weights, self.scoring_disabled))
}
fn disable_scoring(&mut self) {
self.scoring_disabled = true;
}
}

View File

@@ -9,12 +9,14 @@ use Result;
pub struct BooleanWeight {
weights: Vec<(Occur, Box<Weight>)>,
scoring_disabled: bool
}
impl BooleanWeight {
pub fn new(weights: Vec<(Occur, Box<Weight>)>) -> BooleanWeight {
pub fn new(weights: Vec<(Occur, Box<Weight>)>, scoring_disabled: bool) -> BooleanWeight {
BooleanWeight {
weights
weights,
scoring_disabled
}
}
}