mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
Assistant: Prioritize results which exactly match a query
This commit is contained in:
parent
e1099a1757
commit
e510d81567
1 changed files with 24 additions and 11 deletions
|
@ -81,12 +81,18 @@ void AppProvider::query(DeprecatedString const& query, Function<void(Vector<Nonn
|
||||||
auto query_and_arguments = query.split_limit(' ', 2);
|
auto query_and_arguments = query.split_limit(' ', 2);
|
||||||
auto app_name = query_and_arguments.is_empty() ? query : query_and_arguments[0];
|
auto app_name = query_and_arguments.is_empty() ? query : query_and_arguments[0];
|
||||||
auto arguments = query_and_arguments.size() < 2 ? DeprecatedString::empty() : query_and_arguments[1];
|
auto arguments = query_and_arguments.size() < 2 ? DeprecatedString::empty() : query_and_arguments[1];
|
||||||
auto match_result = fuzzy_match(app_name, app_file->name());
|
auto score = 0;
|
||||||
if (!match_result.matched)
|
if (app_name.equals_ignoring_ascii_case(app_file->name()))
|
||||||
continue;
|
score = NumericLimits<int>::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());
|
auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable());
|
||||||
results.append(make_ref_counted<AppResult>(icon.bitmap_for_size(16), app_file->name(), String(), app_file, arguments, match_result.score));
|
results.append(make_ref_counted<AppResult>(icon.bitmap_for_size(16), app_file->name(), String(), app_file, arguments, score));
|
||||||
};
|
};
|
||||||
|
|
||||||
on_complete(move(results));
|
on_complete(move(results));
|
||||||
|
@ -147,17 +153,24 @@ void FileProvider::query(DeprecatedString const& query, Function<void(Vector<Non
|
||||||
if (task.is_canceled())
|
if (task.is_canceled())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto match_result = fuzzy_match(query, path);
|
auto score = 0;
|
||||||
if (!match_result.matched)
|
if (query.equals_ignoring_ascii_case(path)) {
|
||||||
continue;
|
score = NumericLimits<int>::max();
|
||||||
if (match_result.score < 0)
|
} else {
|
||||||
continue;
|
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)
|
if (sorted_results.size() == MAX_SEARCH_RESULTS)
|
||||||
sorted_results.pop_min();
|
sorted_results.pop_min();
|
||||||
|
|
||||||
sorted_results.insert(match_result.score, path);
|
sorted_results.insert(score, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue