issue/50 Small formatting change.

This commit is contained in:
Paul Masurel
2016-11-04 00:11:46 +09:00
parent 9d3c9999cb
commit f2df0bf0e9
19 changed files with 290 additions and 297 deletions

View File

@@ -12,7 +12,7 @@ impl BooleanClause {
pub fn new(query: Box<Query>, occur: Occur) -> BooleanClause {
BooleanClause {
query: query,
occur: occur
occur: occur,
}
}
}
}

View File

@@ -12,11 +12,11 @@ use query::OccurFilter;
///
/// The documents matched by the boolean query are
/// those which
/// * match all of the sub queries associated with the
/// * match all of the sub queries associated with the
/// `Must` occurence
/// * match none of the sub queries associated with the
/// * match none of the sub queries associated with the
/// `MustNot` occurence.
/// * match at least one of the subqueries that is not
/// * match at least one of the subqueries that is not
/// a `MustNot` occurence.
#[derive(Debug)]
pub struct BooleanQuery {
@@ -25,14 +25,11 @@ pub struct BooleanQuery {
impl From<Vec<BooleanClause>> for BooleanQuery {
fn from(clauses: Vec<BooleanClause>) -> BooleanQuery {
BooleanQuery {
clauses: clauses,
}
}
BooleanQuery { clauses: clauses }
}
}
impl Query for BooleanQuery {
fn as_any(&self) -> &Any {
self
}
@@ -41,8 +38,7 @@ impl Query for BooleanQuery {
let sub_weights = try!(self.clauses
.iter()
.map(|clause| clause.query.weight(searcher))
.collect()
);
.collect());
let occurs: Vec<Occur> = self.clauses
.iter()
.map(|clause| clause.occur)
@@ -50,5 +46,4 @@ impl Query for BooleanQuery {
let filter = OccurFilter::new(&occurs);
Ok(box BooleanWeight::new(sub_weights, filter))
}
}

View File

@@ -33,7 +33,7 @@ impl Ord for HeapItem {
}
pub struct BooleanScorer<TScorer: Scorer> {
postings: Vec<TScorer>,
scorers: Vec<TScorer>,
queue: BinaryHeap<HeapItem>,
doc: DocId,
score_combiner: ScoreCombiner,
@@ -43,20 +43,20 @@ pub struct BooleanScorer<TScorer: Scorer> {
impl<TScorer: Scorer> BooleanScorer<TScorer> {
pub fn scorers(&self) -> &[TScorer] {
&self.postings
&self.scorers
}
pub fn new(postings: Vec<TScorer>,
pub fn new(scorers: Vec<TScorer>,
occur_filter: OccurFilter) -> BooleanScorer<TScorer> {
let score_combiner = ScoreCombiner::default_for_num_scorers(postings.len());
let mut non_empty_postings: Vec<TScorer> = Vec::new();
for mut posting in postings {
let score_combiner = ScoreCombiner::default_for_num_scorers(scorers.len());
let mut non_empty_scorers: Vec<TScorer> = Vec::new();
for mut posting in scorers {
let non_empty = posting.advance();
if non_empty {
non_empty_postings.push(posting);
non_empty_scorers.push(posting);
}
}
let heap_items: Vec<HeapItem> = non_empty_postings
let heap_items: Vec<HeapItem> = non_empty_scorers
.iter()
.map(|posting| posting.doc())
.enumerate()
@@ -68,7 +68,7 @@ impl<TScorer: Scorer> BooleanScorer<TScorer> {
})
.collect();
BooleanScorer {
postings: non_empty_postings,
scorers: non_empty_scorers,
queue: BinaryHeap::from(heap_items),
doc: 0u32,
score_combiner: score_combiner,
@@ -77,7 +77,7 @@ impl<TScorer: Scorer> BooleanScorer<TScorer> {
}
}
/// Advances the head of our heap (the segment postings with the lowest doc)
/// Advances the head of our heap (the segment posting with the lowest doc)
/// It will also update the new current `DocId` as well as the term frequency
/// associated with the segment postings.
///
@@ -89,9 +89,9 @@ impl<TScorer: Scorer> BooleanScorer<TScorer> {
fn advance_head(&mut self,) {
{
let mut mutable_head = self.queue.peek_mut().unwrap();
let cur_postings = &mut self.postings[mutable_head.ord as usize];
if cur_postings.advance() {
mutable_head.doc = cur_postings.doc();
let cur_scorers = &mut self.scorers[mutable_head.ord as usize];
if cur_scorers.advance() {
mutable_head.doc = cur_scorers.doc();
return;
}
}
@@ -108,7 +108,7 @@ impl<TScorer: Scorer> DocSet for BooleanScorer<TScorer> {
Some(heap_item) => {
let ord = heap_item.ord as usize;
self.doc = heap_item.doc;
let score = self.postings[ord].score();
let score = self.scorers[ord].score();
self.score_combiner.update(score);
ord_bitset |= 1 << ord;
}
@@ -120,7 +120,7 @@ impl<TScorer: Scorer> DocSet for BooleanScorer<TScorer> {
while let Some(&HeapItem {doc, ord}) = self.queue.peek() {
if doc == self.doc {
let ord = ord as usize;
let score = self.postings[ord].score();
let score = self.scorers[ord].score();
self.score_combiner.update(score);
ord_bitset |= 1 << ord;
}

View File

@@ -11,8 +11,7 @@ pub struct BooleanWeight {
}
impl BooleanWeight {
pub fn new(weights: Vec<Box<Weight>>,
occur_filter: OccurFilter) -> BooleanWeight {
pub fn new(weights: Vec<Box<Weight>>, occur_filter: OccurFilter) -> BooleanWeight {
BooleanWeight {
weights: weights,
occur_filter: occur_filter,
@@ -22,15 +21,12 @@ impl BooleanWeight {
impl Weight for BooleanWeight {
fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {
let sub_scorers: Vec<Box<Scorer + 'a>> = try!(
self.weights
.iter()
.map(|weight| weight.scorer(reader))
.collect()
);
let boolean_scorer = BooleanScorer::new(sub_scorers, self.occur_filter);
let sub_scorers: Vec<Box<Scorer + 'a>> = try!(self.weights
.iter()
.map(|weight| weight.scorer(reader))
.collect());
let boolean_scorer = BooleanScorer::new(sub_scorers, self.occur_filter);
Ok(box boolean_scorer)
}
}