feat: use launch history to break search ranking ties
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user