launcher: better fuzzy query

This commit is contained in:
2 * r + 2 * t 2025-05-07 16:56:10 +10:00
parent 17ff34368d
commit 9b958a8e10
2 changed files with 10 additions and 6 deletions

View file

@ -88,15 +88,17 @@ Singleton {
} }
] ]
readonly property list<var> preppedNames: list.map(a => ({ readonly property list<var> preppedActions: list.map(a => ({
name: Fuzzy.prepare(a.name), name: Fuzzy.prepare(a.name),
desc: Fuzzy.prepare(a.desc),
action: a action: a
})) }))
function fuzzyQuery(search: string): var { function fuzzyQuery(search: string): var {
return Fuzzy.go(search.slice(LauncherConfig.actionPrefix.length), preppedNames, { return Fuzzy.go(search.slice(LauncherConfig.actionPrefix.length), preppedActions, {
all: true, all: true,
key: "name" keys: ["name", "desc"],
scoreFn: r => r[0].score * 0.9 + r[1].score * 0.1
}).map(r => r.obj.action); }).map(r => r.obj.action);
} }

View file

@ -8,15 +8,17 @@ Singleton {
id: root id: root
readonly property list<DesktopEntry> list: DesktopEntries.applications.values.filter(a => !a.noDisplay).sort((a, b) => a.name.localeCompare(b.name)) readonly property list<DesktopEntry> list: DesktopEntries.applications.values.filter(a => !a.noDisplay).sort((a, b) => a.name.localeCompare(b.name))
readonly property list<var> preppedNames: list.map(a => ({ readonly property list<var> preppedApps: list.map(a => ({
name: Fuzzy.prepare(a.name), name: Fuzzy.prepare(a.name),
comment: Fuzzy.prepare(a.comment),
entry: a entry: a
})) }))
function fuzzyQuery(search: string): var { // Idk why list<DesktopEntry> doesn't work function fuzzyQuery(search: string): var { // Idk why list<DesktopEntry> doesn't work
return Fuzzy.go(search, preppedNames, { return Fuzzy.go(search, preppedApps, {
all: true, all: true,
key: "name" keys: ["name", "comment"],
scoreFn: r => r[0].score * 0.9 + r[1].score * 0.1
}).map(r => r.obj.entry); }).map(r => r.obj.entry);
} }