tweak search result ranking

This commit is contained in:
MM20
2025-10-17 15:48:58 +02:00
parent 496ca97dc8
commit 5a575738ac
3 changed files with 5 additions and 4 deletions

View File

@@ -433,8 +433,8 @@ class SearchVM : ViewModel(), KoinComponent {
b.score.score
}
val aTotal = aScore * 0.7f + aWeight.toFloat() * 0.3f
val bTotal = bScore * 0.7f + bWeight.toFloat() * 0.3f
val aTotal = aScore * 0.6f + aWeight.toFloat() * 0.4f
val bTotal = bScore * 0.6f + bWeight.toFloat() * 0.4f
bTotal.compareTo(aTotal)
}

View File

@@ -43,9 +43,10 @@ value class ResultScore private constructor(private val packed: Long) : Comparab
/**
* A total score for the result, combining the similarity with additional factors.
* The score is normalized to be between 0 and 1.
*/
val score: Float
get() = (similarity + (if (isPrefix) 0.8f else 0f) + (if (isSubstring) 0.8f else 0f)) * (if (isPrimary) 1f else 0.8f)
get() = (similarity + (if (isPrefix) 0.2f else 0f) + (if (isSubstring) 0.8f else 0f)).coerceIn(0f, 1f) * (if (isPrimary) 1f else 0.8f)
override fun compareTo(other: ResultScore): Int {
return score.compareTo(other.score)

View File

@@ -183,7 +183,7 @@ interface SearchableDao {
@Query("UPDATE Searchable SET launchCount = launchCount + 1 WHERE `key` = :key")
fun incrementLaunchCount(key: String)
@Query("UPDATE Searchable SET `weight` = `weight` * (1.0 - :alpha) WHERE `key` != :key")
@Query("UPDATE Searchable SET `weight` = `weight` * (1.0 - :alpha) WHERE `key` != :key AND weight > 0.001")
fun reduceWeightExcept(key: String, alpha: Double)
@Query("UPDATE Searchable SET `weight` = `weight` + :alpha * (1.0 - `weight`) WHERE `key` == :key")