Skip to content

Commit 85d5b8e

Browse files
committed
fix(search): dedup "did you mean?" suggestions across repos
1 parent a3a4431 commit 85d5b8e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

crates/soar-operations/src/search.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{HashMap, HashSet};
22

33
use nucleo_matcher::{
44
pattern::{CaseMatching, Normalization, Pattern},
@@ -157,13 +157,18 @@ pub async fn suggest_similar(
157157

158158
let scored = score_candidates(query, &candidates);
159159

160+
// `scored` is sorted by score descending, so the first time we see a
161+
// package name is its best-scoring occurrence. Dedup by name to avoid
162+
// showing the same package once per repo that provides it.
163+
let mut seen = HashSet::new();
160164
let suggestions: Vec<String> = scored
161165
.into_iter()
162-
.take(max)
163-
.map(|(_, idx)| {
166+
.filter_map(|(_, idx)| {
164167
let (_, candidate) = &candidates[idx];
165-
candidate.pkg_name.clone()
168+
seen.insert(candidate.pkg_name.clone())
169+
.then(|| candidate.pkg_name.clone())
166170
})
171+
.take(max)
167172
.collect();
168173

169174
Ok(suggestions)

0 commit comments

Comments
 (0)