Skip to content

Commit c6db282

Browse files
committed
plugins/applications: Rework weighting logic for matches
Fixes #249 Squashed commit of the following: commit ad5f0a4 Author: Arno Vaara <[email protected]> Date: Tue Sep 16 12:39:48 2025 +0300 plugins/applications: Adjusted weights commit 3440675 Author: Arno Vaara <[email protected]> Date: Mon Sep 15 17:01:20 2025 +0300 plugins/applications: Adjusted weighting logic commit 383732e Author: Arno Vaara <[email protected]> Date: Mon Sep 15 16:29:57 2025 +0300 plugins/applications: Change application result scoring
1 parent 5c57704 commit c6db282

File tree

1 file changed

+20
-18
lines changed
  • plugins/applications/src

1 file changed

+20
-18
lines changed

plugins/applications/src/lib.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,39 +176,41 @@ pub fn init(config_dir: RString) -> State {
176176

177177
#[get_matches]
178178
pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
179-
let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().smart_case();
179+
let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case();
180180
let mut entries = state
181181
.entries
182182
.iter()
183183
.filter_map(|(entry, id)| {
184-
// Can be replaced by `Iterator::intersperse` once the API becomes stable.
185-
fn prefix_sep(i: &Option<String>) -> impl Iterator<Item = &str> + '_ {
186-
i.as_deref()
187-
.map(|s| [" ", s].into_iter())
188-
.into_iter()
189-
.flatten()
190-
}
191-
192-
let app_names = ([&*entry.name].into_iter())
193-
.chain(prefix_sep(&entry.localized_name))
194-
.chain(prefix_sep(&entry.desc))
195-
.collect::<String>();
196-
197-
let app_score = matcher.fuzzy_match(&app_names, &input).unwrap_or(0);
184+
let name_score = matcher.fuzzy_match(&entry.name, &input).unwrap_or(0).max(
185+
matcher
186+
.fuzzy_match(&entry.localized_name(), &input)
187+
.unwrap_or(0),
188+
);
189+
let desc_score = entry
190+
.desc
191+
.as_ref()
192+
.and_then(|desc| matcher.fuzzy_match(desc, &input))
193+
.unwrap_or(0);
198194

199195
let keyword_score = (entry.keywords.iter())
200196
.chain(entry.localized_keywords.iter().flat_map(|k| k.iter()))
201-
.map(|keyword| matcher.fuzzy_match(keyword, &input).unwrap_or(0))
202-
.sum::<i64>();
197+
.filter_map(|keyword| matcher.fuzzy_match(keyword, &input))
198+
.max()
199+
.unwrap_or(0);
203200

204-
let mut score = (app_score * 25 + keyword_score) - entry.offset;
201+
let mut score = (name_score * 10 + desc_score + keyword_score) - entry.offset;
205202

206203
// prioritize actions
207204
if entry.is_action {
208205
score *= 2;
209206
}
210207

208+
// Score cutoff
211209
if score > 0 {
210+
println!(
211+
"{} {name_score} {desc_score} {keyword_score} = {score}",
212+
entry.name
213+
);
212214
Some((entry, *id, score))
213215
} else {
214216
None

0 commit comments

Comments
 (0)