Improve app result ranking
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package de.mm20.launcher2.database
|
||||
|
||||
import android.util.Log
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.MapColumn
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
@@ -201,6 +201,9 @@ interface SearchableDao {
|
||||
@Query("SELECT `key` FROM Searchable WHERE `key` IN (:keys) ORDER BY `weight` DESC, pinPosition DESC")
|
||||
fun sortByWeight(keys: List<String>): Flow<List<String>>
|
||||
|
||||
@Query("SELECT `key`, `weight` FROM Searchable WHERE `key` IN (:keys)")
|
||||
fun getWeights(keys: List<String>): Flow<Map<@MapColumn(columnName = "key") String, @MapColumn(columnName = "weight") Double>>
|
||||
|
||||
@Query("SELECT hidden FROM Searchable WHERE `key` = :key UNION SELECT 0 as hidden ORDER BY hidden DESC LIMIT 1")
|
||||
fun getVisibility(key: String): Flow<Int>
|
||||
|
||||
|
||||
+7
@@ -103,6 +103,8 @@ interface SavableSearchableRepository : Backupable {
|
||||
|
||||
fun sortByWeight(keys: List<String>): Flow<List<String>>
|
||||
|
||||
fun getWeights(keys: List<String>): Flow<Map<String, Double>>
|
||||
|
||||
/**
|
||||
* Remove this item from the Searchable database
|
||||
*/
|
||||
@@ -370,6 +372,11 @@ internal class SavableSearchableRepositoryImpl(
|
||||
return database.searchableDao().sortByWeight(keys)
|
||||
}
|
||||
|
||||
override fun getWeights(keys: List<String>): Flow<Map<String, Double>> {
|
||||
if (keys.size > 999) return flowOf(emptyMap())
|
||||
return database.searchableDao().getWeights(keys)
|
||||
}
|
||||
|
||||
private suspend fun fromDatabaseEntity(entity: SavedSearchableEntity): SavedSearchable {
|
||||
val deserializer: SearchableDeserializer? = try {
|
||||
get(named(entity.type))
|
||||
|
||||
Reference in New Issue
Block a user