From e510d81567bbde82baceb3a24bb4a6c3429fae30 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 21 Sep 2023 19:35:32 +0100 Subject: [PATCH] Assistant: Prioritize results which exactly match a query --- Userland/Applications/Assistant/Providers.cpp | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Userland/Applications/Assistant/Providers.cpp b/Userland/Applications/Assistant/Providers.cpp index b8c6e45e56e..c0c66a46873 100644 --- a/Userland/Applications/Assistant/Providers.cpp +++ b/Userland/Applications/Assistant/Providers.cpp @@ -81,12 +81,18 @@ void AppProvider::query(DeprecatedString const& query, Functionname()); - if (!match_result.matched) - continue; + auto score = 0; + if (app_name.equals_ignoring_ascii_case(app_file->name())) + score = NumericLimits::max(); + else { + auto match_result = fuzzy_match(app_name, app_file->name()); + if (!match_result.matched) + continue; + score = match_result.score; + } auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable()); - results.append(make_ref_counted(icon.bitmap_for_size(16), app_file->name(), String(), app_file, arguments, match_result.score)); + results.append(make_ref_counted(icon.bitmap_for_size(16), app_file->name(), String(), app_file, arguments, score)); }; on_complete(move(results)); @@ -147,17 +153,24 @@ void FileProvider::query(DeprecatedString const& query, Function::max(); + } else { + auto match_result = fuzzy_match(query, path); + if (!match_result.matched) + continue; + if (match_result.score < 0) + continue; - if (sorted_results.size() < MAX_SEARCH_RESULTS || match_result.score > sorted_results.peek_min_key()) { + score = match_result.score; + } + + if (sorted_results.size() < MAX_SEARCH_RESULTS || score > sorted_results.peek_min_key()) { if (sorted_results.size() == MAX_SEARCH_RESULTS) sorted_results.pop_min(); - sorted_results.insert(match_result.score, path); + sorted_results.insert(score, path); } }