fix(cli-rs): rank model searches with spaces by every word

This commit is contained in:
Simon Klee
2026-11-06 23:26:22 +01:00
Unverified
parent 4e2a226809
commit 57c42054c8
3 changed files with 22 additions and 20 deletions
@@ -256,8 +256,14 @@ fn catalog_options(
option
};
if !needle.is_empty() {
let matches =
fuzzy::go(needle, &rows, |row| [Some(row.title.as_str()), row.category.as_deref()], fuzzy::best_key, 0.0);
let matches = fuzzy::go_scored(
needle,
&rows,
|row| [Some(row.title.as_str()), row.category.as_deref()],
|_, score, _| score,
0.0,
usize::MAX,
);
let mut results: Vec<Row> = matches.into_iter().map(|index| rows[index].clone()).collect();
sort_rows(&mut results, false);
prioritize(&mut results, |row| &row.value, &favorite_priority);
@@ -342,6 +342,20 @@ fn a_filter_typed_before_the_limits_arrive_stays() {
assert!(!screen.contains("Claude Haiku"), "the filter was lost:\n{screen}");
}
#[test]
fn a_search_with_spaces_ranks_by_its_words_across_title_and_provider() {
let h = mount();
h.app.press("ctrl+x");
h.app.press("m");
h.wait_for("Search models");
// fuzzysort's default score sums each word's best key: "Grok Code" (OpenCode) before "Claude Haiku".
h.app.type_text("o c");
let screen = h.wait_for("Grok Code");
let at = |name: &str| screen.find(name).unwrap_or_else(|| panic!("no {name}:\n{screen}"));
assert!(at("Grok Code") < at("Claude Haiku"), "{screen}");
assert!(at("Claude Haiku") < at("Claude Sonnet"), "{screen}");
}
#[test]
fn the_prompt_shows_and_submits_the_model_picked_in_the_dialog() {
let h = mount();
@@ -1,18 +0,0 @@
# DLG12: the model pickers rank multi-word searches with fuzzysort's per-key score
## TypeScript
`DialogConnectedModels` (`packages/tui/src/component/dialog-model.tsx:182-194`) and `DialogFreeModels`
(`component/dialog-model-free.tsx:39-43`) filter with `fuzzysort.go(needle, options, { keys })`. A search with
spaces is split into words, and each option scores by the words it matches across its keys.
## Rust
The pickers list the same models in the same order, with the same header description, `*` favorite marker,
actions, and `ModelDetail` line below the list. A search with spaces ranks with fuzzysort's per-key default score
instead of its space-split score. Single-word searches rank the same.
## Reason
U.3's `fuzzy::go` takes a score function over per-key scores only. Port the space-split scoring there, then drop
this file.