diff --git a/src/postings/postings.rs b/src/postings/postings.rs index 01a9f1080b..682e61393f 100644 --- a/src/postings/postings.rs +++ b/src/postings/postings.rs @@ -15,6 +15,7 @@ pub trait Postings: DocSet + 'static { fn term_freq(&self) -> u32; /// Returns the positions offsetted with a given value. + /// It is not necessary to clear the `output` before calling this method. /// The output vector will be resized to the `term_freq`. fn positions_with_offset(&mut self, offset: u32, output: &mut Vec); diff --git a/src/query/phrase_prefix_query/phrase_prefix_scorer.rs b/src/query/phrase_prefix_query/phrase_prefix_scorer.rs index 4e76d49299..b456e4e403 100644 --- a/src/query/phrase_prefix_query/phrase_prefix_scorer.rs +++ b/src/query/phrase_prefix_query/phrase_prefix_scorer.rs @@ -97,6 +97,7 @@ pub struct PhrasePrefixScorer { suffixes: Vec, suffix_offset: u32, phrase_count: u32, + suffix_position_buffer: Vec, } impl PhrasePrefixScorer { @@ -140,6 +141,7 @@ impl PhrasePrefixScorer { suffixes, suffix_offset: (max_offset - suffix_pos) as u32, phrase_count: 0, + suffix_position_buffer: Vec::with_capacity(100), }; if phrase_prefix_scorer.doc() != TERMINATED && !phrase_prefix_scorer.matches_prefix() { phrase_prefix_scorer.advance(); @@ -153,7 +155,6 @@ impl PhrasePrefixScorer { fn matches_prefix(&mut self) -> bool { let mut count = 0; - let mut positions = Vec::new(); let current_doc = self.doc(); let pos_matching = self.phrase_scorer.get_intersection(); for suffix in &mut self.suffixes { @@ -162,8 +163,8 @@ impl PhrasePrefixScorer { } let doc = suffix.seek(current_doc); if doc == current_doc { - suffix.positions_with_offset(self.suffix_offset, &mut positions); - count += intersection_count(pos_matching, &positions); + suffix.positions_with_offset(self.suffix_offset, &mut self.suffix_position_buffer); + count += intersection_count(pos_matching, &self.suffix_position_buffer); } } self.phrase_count = count as u32;