refactor(post-search): collect at least 2 documents from each query source (#948)

This commit refactors the code that evenly collects documents from query
sources to let it collect at least 2 documents in every source, which
could correct the case when `max_hits_per_source` is 0. This was possible
with the previous impl, no longer allowed after this commit
This commit is contained in:
SteveLauC
2025-10-27 10:07:57 +08:00
committed by GitHub
parent 4a627cb32e
commit 03954748b6
2 changed files with 3 additions and 6 deletions

View File

@@ -46,6 +46,7 @@ chore: use a custom log directory #930
chore: bump tauri_nspanel to v2.1 #933
refactor: show_coco/hide_coco now use NSPanel's function on macOS #933
refactor: procedure that convert_pages() into a func #934
refactor(post-search): collect at least 2 documents from each query source #948
refactor: custom_version_comparator() now compares semantic versions #941
## 0.8.0 (2025-09-28)

View File

@@ -286,10 +286,8 @@ async fn query_coco_fusion_multi_query_sources(
let mut final_hits_grouped_by_source_id: HashMap<String, Vec<QueryHits>> = HashMap::new();
let mut pruned: HashMap<&str, &[QueryHits]> = HashMap::new();
// max_hits_per_source could be 0, then `final_hits_grouped_by_source_id`
// would be empty. But we don't need to worry about this case as we will
// populate hits later.
let max_hits_per_source = size as usize / n_sources;
// Include at least 2 hits from each query source
let max_hits_per_source = (size as usize / n_sources).max(2);
for (source_id, hits) in all_hits_grouped_by_source_id.iter() {
let hits_taken = if hits.len() > max_hits_per_source {
pruned.insert(&source_id, &hits[max_hits_per_source..]);
@@ -376,8 +374,6 @@ async fn query_coco_fusion_multi_query_sources(
});
// Truncate `final_hits` in case it contains more than `size` hits
//
// Technically, we are safe to not do this. But since it is trivial, double-check it.
final_hits.truncate(size as usize);
if final_hits.len() < 5 {