feat: use launch history to break search ranking ties

This commit is contained in:
2026-10-12 14:17:29 +02:00
parent a0a6f25c03
commit 0da8b8e241
5 changed files with 57 additions and 14 deletions
+16 -10
View File
@@ -40,16 +40,22 @@ public final class LaunchHistory {
}
public func suggestions(in applications: [Application]) -> [Application] {
applications.sorted { lhs, rhs in
let left = usage[lhs.id]
let right = usage[rhs.id]
let leftCount = left?.count ?? 0
let rightCount = right?.count ?? 0
if leftCount != rightCount { return leftCount > rightCount }
if let left, let right, left.lastLaunch != right.lastLaunch {
return left.lastLaunch > right.lastLaunch
}
return alphabetical(lhs, rhs)
applications.sorted(by: preferred)
}
public func results(for query: String, in applications: [Application]) -> [Application] {
ApplicationSearch.results(for: query, in: applications, breakingTiesWith: preferred)
}
private func preferred(_ lhs: Application, _ rhs: Application) -> Bool {
let left = usage[lhs.id]
let right = usage[rhs.id]
let leftCount = left?.count ?? 0
let rightCount = right?.count ?? 0
if leftCount != rightCount { return leftCount > rightCount }
if let left, let right, left.lastLaunch != right.lastLaunch {
return left.lastLaunch > right.lastLaunch
}
return alphabetical(lhs, rhs)
}
}