Improve app and shortcut query matching

This commit is contained in:
MM20 2022-12-21 19:37:38 +01:00
parent 41a0157983
commit aa69fb5f42
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 7 additions and 5 deletions

View File

@ -170,9 +170,10 @@ internal class AppRepositoryImpl(
private fun matches(label: String, query: String): Boolean {
val normalizedLabel = label.normalize()
val normalizedQuery = query.normalize()
if (normalizedLabel.contains(normalizedQuery)) return true
val fuzzyScore = FuzzyScore(Locale.getDefault())
return fuzzyScore.fuzzyScore(label, query) >= query.length * 1.5 ||
fuzzyScore.fuzzyScore(normalizedLabel, query.normalize()) >= query.length * 1.5
return fuzzyScore.fuzzyScore(normalizedLabel, normalizedQuery) >= query.length * 1.5
}
private fun getActivityByComponentName(componentName: ComponentName?): LauncherApp? {

View File

@ -221,9 +221,10 @@ internal class AppShortcutRepositoryImpl(
private fun matches(label: String, query: String): Boolean {
val labelLatin = label.normalize()
val normalizedLabel = label.normalize()
val normalizedQuery = query.normalize()
if (normalizedLabel.contains(normalizedQuery)) return true
val fuzzyScore = FuzzyScore(Locale.getDefault())
return fuzzyScore.fuzzyScore(label, query) >= query.length * 1.5 ||
fuzzyScore.fuzzyScore(labelLatin, query.normalize()) >= query.length * 1.5
return fuzzyScore.fuzzyScore(normalizedLabel, normalizedQuery) >= query.length * 1.5
}
}