refactor(service): tweak fuzzy search config
Some checks failed
test / test (push) Has been cancelled

This commit is contained in:
Pig Fang 2025-12-23 16:22:56 +08:00
parent 4647b1937f
commit 4245bcf807
No known key found for this signature in database
GPG key ID: A8198F548DADA9E2

View file

@ -49,9 +49,15 @@ pub fn fuzzy_search<S>(haystack: impl IntoIterator<Item = S>, needle: &str) -> O
where
S: AsRef<str>,
{
use fuzzy_matcher::{FuzzyMatcher, skim::SkimMatcherV2};
use fuzzy_matcher::{
FuzzyMatcher,
skim::{SkimMatcherV2, SkimScoreConfig},
};
let matcher = SkimMatcherV2::default();
let matcher = SkimMatcherV2::default().score_config(SkimScoreConfig {
bonus_head: -12,
..Default::default()
});
haystack
.into_iter()
.filter_map(|name| {
@ -59,7 +65,7 @@ where
.fuzzy_match(name.as_ref(), needle)
.map(|score| (score, name))
})
.max_by_key(|(score, _)| *score)
.min_by_key(|(score, _)| *score)
.map(|(_, guess)| guess)
}