Improve app result ranking

This commit is contained in:
MM20
2024-10-12 22:16:10 +02:00
parent 422928321e
commit bf6e963545
10 changed files with 143 additions and 20 deletions
@@ -14,6 +14,7 @@ import de.mm20.launcher2.ktx.normalize
import de.mm20.launcher2.profiles.Profile
import de.mm20.launcher2.profiles.ProfileManager
import de.mm20.launcher2.search.Application
import de.mm20.launcher2.search.ResultScore
import de.mm20.launcher2.search.SearchableRepository
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
@@ -37,6 +38,7 @@ interface AppRepository : SearchableRepository<Application> {
packageName: String,
user: UserHandle,
): Flow<Application?>
fun findMany(): Flow<ImmutableList<Application>>
}
@@ -244,8 +246,13 @@ internal class AppRepositoryImpl(
if (query.isEmpty()) {
appResults.addAll(apps)
} else {
appResults.addAll(apps.filter {
matches(it.label, query)
appResults.addAll(apps.mapNotNull {
it.copy(
score = ResultScore(
query = query,
primaryFields = listOf(it.label),
)
).takeIf { it.score.score >= 0.8f }
})
val componentName = ComponentName.unflattenFromString(query)
@@ -28,6 +28,7 @@ import de.mm20.launcher2.icons.TransparentLayer
import de.mm20.launcher2.ktx.getSerialNumber
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.search.Application
import de.mm20.launcher2.search.ResultScore
import de.mm20.launcher2.search.SearchableSerializer
import de.mm20.launcher2.search.StoreLink
import kotlinx.coroutines.Dispatchers
@@ -40,6 +41,7 @@ internal data class LauncherApp(
override val isSuspended: Boolean = false,
internal val userSerialNumber: Long,
override val labelOverride: String? = null,
override val score: ResultScore = ResultScore.Zero,
) : Application {
override val componentName: ComponentName
@@ -48,11 +50,12 @@ internal data class LauncherApp(
override val label: String = launcherActivityInfo.label.toString()
constructor(context: Context, launcherActivityInfo: LauncherActivityInfo) : this(
constructor(context: Context, launcherActivityInfo: LauncherActivityInfo, score: ResultScore = ResultScore.Zero) : this(
launcherActivityInfo,
versionName = getPackageVersionName(context, launcherActivityInfo.applicationInfo.packageName),
isSuspended = launcherActivityInfo.applicationInfo.flags and ApplicationInfo.FLAG_SUSPENDED != 0,
userSerialNumber = launcherActivityInfo.user.getSerialNumber(context)
userSerialNumber = launcherActivityInfo.user.getSerialNumber(context),
score = score,
)
override val user: UserHandle