From f540a69ac3d3b954b53734492e7b8ef3158ddc4d Mon Sep 17 00:00:00 2001 From: Tee Jun hui Date: Wed, 5 Feb 2025 16:19:05 +0800 Subject: [PATCH 1/4] add 1 to index so it points to correct position --- crates/milli/src/search/new/bucket_sort.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/milli/src/search/new/bucket_sort.rs b/crates/milli/src/search/new/bucket_sort.rs index 8f1deb265..d0b7d258c 100644 --- a/crates/milli/src/search/new/bucket_sort.rs +++ b/crates/milli/src/search/new/bucket_sort.rs @@ -178,6 +178,7 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( if current_score < ranking_score_threshold { all_candidates -= bucket | &ranking_rule_universes[cur_ranking_rule_index]; back!(); + cur_ranking_rule_index += 1; continue; } } @@ -213,6 +214,7 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( continue; } + let Some(next_bucket) = ranking_rules[cur_ranking_rule_index].next_bucket( ctx, logger, @@ -242,7 +244,9 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( if current_score < ranking_score_threshold { all_candidates -= next_bucket.candidates | &ranking_rule_universes[cur_ranking_rule_index]; + back!(); + cur_ranking_rule_index += 1; continue; } } From 8c8cc59a6c1a53a80eb63ee0637a402be20449e9 Mon Sep 17 00:00:00 2001 From: Tee Jun hui Date: Wed, 5 Feb 2025 16:41:24 +0800 Subject: [PATCH 2/4] remove new line added by accident --- crates/milli/src/search/new/bucket_sort.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/milli/src/search/new/bucket_sort.rs b/crates/milli/src/search/new/bucket_sort.rs index d0b7d258c..172bdb3f9 100644 --- a/crates/milli/src/search/new/bucket_sort.rs +++ b/crates/milli/src/search/new/bucket_sort.rs @@ -214,7 +214,6 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( continue; } - let Some(next_bucket) = ranking_rules[cur_ranking_rule_index].next_bucket( ctx, logger, @@ -244,7 +243,6 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( if current_score < ranking_score_threshold { all_candidates -= next_bucket.candidates | &ranking_rule_universes[cur_ranking_rule_index]; - back!(); cur_ranking_rule_index += 1; continue; From f9807ba32ef36fb3980299e07dec91df49b58bff Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 19 Mar 2025 11:33:44 +0100 Subject: [PATCH 3/4] Fix logic when results are below the threshold --- crates/milli/src/search/new/bucket_sort.rs | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/crates/milli/src/search/new/bucket_sort.rs b/crates/milli/src/search/new/bucket_sort.rs index 172bdb3f9..a659dd226 100644 --- a/crates/milli/src/search/new/bucket_sort.rs +++ b/crates/milli/src/search/new/bucket_sort.rs @@ -173,17 +173,18 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( ranking_rule_scores.push(ScoreDetails::Skipped); // remove candidates from the universe without adding them to result if their score is below the threshold - if let Some(ranking_score_threshold) = ranking_score_threshold { - let current_score = ScoreDetails::global_score(ranking_rule_scores.iter()); - if current_score < ranking_score_threshold { - all_candidates -= bucket | &ranking_rule_universes[cur_ranking_rule_index]; - back!(); - cur_ranking_rule_index += 1; - continue; - } - } + let is_below_threshold = + ranking_score_threshold.is_some_and(|ranking_score_threshold| { + let current_score = ScoreDetails::global_score(ranking_rule_scores.iter()); + current_score < ranking_score_threshold + }); - maybe_add_to_results!(bucket); + if is_below_threshold { + all_candidates -= &bucket; + all_candidates -= &ranking_rule_universes[cur_ranking_rule_index]; + } else { + maybe_add_to_results!(bucket); + } ranking_rule_scores.pop(); @@ -238,24 +239,24 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( ); // remove candidates from the universe without adding them to result if their score is below the threshold - if let Some(ranking_score_threshold) = ranking_score_threshold { + let is_below_threshold = ranking_score_threshold.is_some_and(|ranking_score_threshold| { let current_score = ScoreDetails::global_score(ranking_rule_scores.iter()); - if current_score < ranking_score_threshold { - all_candidates -= - next_bucket.candidates | &ranking_rule_universes[cur_ranking_rule_index]; - back!(); - cur_ranking_rule_index += 1; - continue; - } - } + current_score < ranking_score_threshold + }); ranking_rule_universes[cur_ranking_rule_index] -= &next_bucket.candidates; if cur_ranking_rule_index == ranking_rules_len - 1 || (scoring_strategy == ScoringStrategy::Skip && next_bucket.candidates.len() <= 1) || cur_offset + (next_bucket.candidates.len() as usize) < from + || is_below_threshold { - maybe_add_to_results!(next_bucket.candidates); + if is_below_threshold { + all_candidates -= + next_bucket.candidates | &ranking_rule_universes[cur_ranking_rule_index]; + } else { + maybe_add_to_results!(next_bucket.candidates); + } ranking_rule_scores.pop(); continue; } From 0656a0d515044f72f9043e42e28331a0fe4fd8cf Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 1 Apr 2025 14:25:27 +0200 Subject: [PATCH 4/4] Optimize roaring operation Co-authored-by: Many the fish --- crates/milli/src/search/new/bucket_sort.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/milli/src/search/new/bucket_sort.rs b/crates/milli/src/search/new/bucket_sort.rs index a659dd226..ca7a4a986 100644 --- a/crates/milli/src/search/new/bucket_sort.rs +++ b/crates/milli/src/search/new/bucket_sort.rs @@ -252,8 +252,8 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( || is_below_threshold { if is_below_threshold { - all_candidates -= - next_bucket.candidates | &ranking_rule_universes[cur_ranking_rule_index]; + all_candidates -= &next_bucket.candidates; + all_candidates -= &ranking_rule_universes[cur_ranking_rule_index]; } else { maybe_add_to_results!(next_bucket.candidates); }