launcher: better at mixing result

This commit is contained in:
Lemmy
2026-01-23 10:30:45 -05:00
parent b0d6a0c076
commit f6794f88d6
3 changed files with 17 additions and 3 deletions
+12 -1
View File
@@ -461,12 +461,23 @@ SmartPanel {
}
} else {
// Regular search - let providers contribute results
let allResults = [];
for (let provider of providers) {
if (provider.handleSearch) {
const providerResults = provider.getResults(searchText);
results = results.concat(providerResults);
allResults = allResults.concat(providerResults);
}
}
// Sort by _score (higher = better match), items without _score go first
if (searchText.trim() !== "") {
allResults.sort((a, b) => {
const sa = a._score !== undefined ? a._score : 0;
const sb = b._score !== undefined ? b._score : 0;
return sb - sa;
});
}
results = allResults;
}
// Update activeProvider only after computing new state to avoid UI flicker
@@ -493,7 +493,7 @@ Item {
else
nonFav.push(r);
}
return fav.concat(nonFav).map(result => createResultEntry(result.obj));
return fav.concat(nonFav).map(result => createResultEntry(result.obj, result.score));
} else {
// Fallback to simple search
const searchTerm = query.toLowerCase();
@@ -531,13 +531,14 @@ Item {
}
}
function createResultEntry(app) {
function createResultEntry(app, score) {
return {
"appId": getAppKey(app),
"name": app.name || "Unknown",
"description": app.genericName || app.comment || "",
"icon": app.icon || "application-x-executable",
"isImage": false,
"_score": score !== undefined ? score : 0,
"provider": root,
"onActivate": function () {
// Close the launcher/SmartPanel immediately without any animations.
@@ -75,6 +75,7 @@ Item {
let launcherItems = [];
for (let i = 0; i < results.length; i++) {
const entry = results[i].obj;
const score = results[i].score;
const tabName = I18n.tr(entry.tabLabel);
const subTabName = entry.subTabName || "";
const breadcrumb = subTabName ? (tabName + " " + subTabName) : tabName;
@@ -85,6 +86,7 @@ Item {
"icon": "settings",
"isTablerIcon": true,
"isImage": false,
"_score": score,
"provider": root,
"onActivate": createActivateHandler(entry)
});