From 322286ee16fe0d50e7863b8cbc32ef6d8d93122f Mon Sep 17 00:00:00 2001 From: James Sewell Date: Sun, 26 Apr 2026 00:13:07 +1200 Subject: [PATCH] Tighen Block-Max in single-scorer (#2897) In the Block-Max WAND single-scorer, it uses block_max_score() < threshold, whereas the multi-term one uses block_max_score_upperbound <= threshold. As both of these are guarded later on with if score > threshold we can use the more efficent form in single-scorer. Single-scorer block skip (<, should be <=): https://github.com/quickwit-oss/tantivy/blob/main/src/query/boolean_query/block_wand.rs#L231 Multi-scorer block skip (already <=): https://github.com/quickwit-oss/tantivy/blob/main/src/query/boolean_query/block_wand.rs#L179 Single-scorer per-doc guard (>): https://github.com/quickwit-oss/tantivy/blob/main/src/query/boolean_query/block_wand.rs#L246 Multi-scorer per-doc guard (>): https://github.com/quickwit-oss/tantivy/blob/main/src/query/boolean_query/block_wand.rs#L206 This will improve performance when there are many identical scores. --- src/query/boolean_query/block_wand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/boolean_query/block_wand.rs b/src/query/boolean_query/block_wand.rs index 6b2f2d6e3..fce4b3fe2 100644 --- a/src/query/boolean_query/block_wand.rs +++ b/src/query/boolean_query/block_wand.rs @@ -228,7 +228,7 @@ pub fn block_wand_single_scorer( loop { // We position the scorer on a block that can reach // the threshold. - while scorer.block_max_score() < threshold { + while scorer.block_max_score() <= threshold { let last_doc_in_block = scorer.last_doc_in_block(); if last_doc_in_block == TERMINATED { return;