From e90df3ff20eb3d33807aaca89c3b7eb29c44fe98 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Sat, 25 Apr 2026 23:04:09 +0200 Subject: [PATCH] Claude CR comment --- src/postings/block_segment_postings.rs | 14 +++++++++++-- .../boolean_query/block_wand_intersection.rs | 5 +++-- src/query/boolean_query/boolean_weight.rs | 20 +++++++++---------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/postings/block_segment_postings.rs b/src/postings/block_segment_postings.rs index 11f2a3e92..61a968131 100644 --- a/src/postings/block_segment_postings.rs +++ b/src/postings/block_segment_postings.rs @@ -25,7 +25,7 @@ fn max_score>(mut it: I) -> Option { pub struct BlockSegmentPostings { pub(crate) doc_decoder: BlockDecoder, block_loaded: bool, - pub(crate) freq_decoder: BlockDecoder, + freq_decoder: BlockDecoder, freq_reading_option: FreqReadingOption, block_max_score_cache: Option, doc_freq: u32, @@ -249,6 +249,12 @@ impl BlockSegmentPostings { /// Returns the length of the current block. /// + /// Returns the decoded term-frequency buffer for the current block. + #[inline] + pub(crate) fn freq_output_array(&self) -> &[u32] { + self.freq_decoder.output_array() + } + /// All blocks have a length of `NUM_DOCS_PER_BLOCK`, /// except the last block that may have a length /// of any number between 1 and `NUM_DOCS_PER_BLOCK - 1` @@ -291,11 +297,15 @@ impl BlockSegmentPostings { /// `.load_block()` needs to be called manually afterwards. /// If all docs are smaller than target, the block loaded may be empty, /// or be the last an incomplete VInt block. - pub(crate) fn seek_block(&mut self, target_doc: DocId) -> bool { + pub(crate) fn seek_block(&mut self, target_doc: DocId) { if self.skip_reader.seek(target_doc) { self.block_max_score_cache = None; self.block_loaded = false; } + } + + #[inline] + pub(crate) fn has_remaining_docs(&self) -> bool { self.skip_reader.has_remaining_docs() } diff --git a/src/query/boolean_query/block_wand_intersection.rs b/src/query/boolean_query/block_wand_intersection.rs index bb7203091..0157fc74f 100644 --- a/src/query/boolean_query/block_wand_intersection.rs +++ b/src/query/boolean_query/block_wand_intersection.rs @@ -67,7 +67,8 @@ pub(crate) fn block_wand_intersection( let mut secondary_block_max_scores = [0.0f32; 16]; let num_secondaries = secondaries.len(); for (idx, secondary) in secondaries.iter_mut().enumerate() { - if !secondary.block_cursor().seek_block(doc) { + secondary.block_cursor().seek_block(doc); + if !secondary.block_cursor().has_remaining_docs() { return; } window_end = window_end.min(secondary.last_doc_in_block()); @@ -111,7 +112,7 @@ pub(crate) fn block_wand_intersection( .min(block_cursor.block_len()); let block_docs = &block_cursor.doc_decoder.output_array()[start_idx..end_idx]; - let block_freqs = &block_cursor.freq_decoder.output_array()[start_idx..end_idx]; + let block_freqs = &block_cursor.freq_output_array()[start_idx..end_idx]; // Pass 1: Batch-compute leader BM25 scores and branchlessly filter // candidates that can't beat the threshold. diff --git a/src/query/boolean_query/boolean_weight.rs b/src/query/boolean_query/boolean_weight.rs index ba3aea3c7..65760682b 100644 --- a/src/query/boolean_query/boolean_weight.rs +++ b/src/query/boolean_query/boolean_weight.rs @@ -508,11 +508,11 @@ impl Weight for BooleanWeight { - let mut intersection = into_box_scorer( - SpecializedScorer::TermIntersection(term_scorers), - &self.score_combiner_fn, - num_docs, - ); + let boxed_scorers: Vec> = term_scorers + .into_iter() + .map(|term_scorer| Box::new(term_scorer) as Box) + .collect(); + let mut intersection = intersect_scorers(boxed_scorers, num_docs); for_each_scorer(intersection.as_mut(), callback); } SpecializedScorer::Other(mut scorer) => { @@ -538,11 +538,11 @@ impl Weight for BooleanWeight { - let mut intersection = into_box_scorer( - SpecializedScorer::TermIntersection(term_scorers), - DoNothingCombiner::default, - num_docs, - ); + let boxed_scorers: Vec> = term_scorers + .into_iter() + .map(|term_scorer| Box::new(term_scorer) as Box) + .collect(); + let mut intersection = intersect_scorers(boxed_scorers, num_docs); for_each_docset_buffered(intersection.as_mut(), &mut buffer, callback); } SpecializedScorer::Other(mut scorer) => {