fix: key search result rows by dictionary, offset and word
Paging result rows had no keys and were matched by position: appended pages and query diffs could not reuse row state. Keys derived from dictionaryPath+offset+word are stable per row, and the paging source collapses duplicate entries for one dictionary card: case and diacritic alias variants of a headword share the normalized word, so entries are deduplicated by dictionaryPath+word+offset before emitting.
This commit is contained in:
@@ -46,9 +46,8 @@ class IndexEntryPagingSource(
|
|||||||
|
|
||||||
private data class EmittedKey(
|
private data class EmittedKey(
|
||||||
val dictPosition: Int,
|
val dictPosition: Int,
|
||||||
val originalWord: String,
|
val word: String,
|
||||||
val offset: Long,
|
val offset: Long
|
||||||
val length: Int
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val emittedArticles = HashSet<EmittedKey>()
|
private val emittedArticles = HashSet<EmittedKey>()
|
||||||
@@ -103,6 +102,7 @@ class IndexEntryPagingSource(
|
|||||||
val normalizedQuery = query.sanitizeQuery().lowercase().trim()
|
val normalizedQuery = query.sanitizeQuery().lowercase().trim()
|
||||||
val ranked = rawResults.map { it.second }
|
val ranked = rawResults.map { it.second }
|
||||||
.rankBySearchRelevance(SearchRankingContext(normalizedQuery))
|
.rankBySearchRelevance(SearchRankingContext(normalizedQuery))
|
||||||
|
.distinctBy { Triple(it.dictionaryPath, it.word, it.offset.value) }
|
||||||
|
|
||||||
rawResults.forEach { (position, entry) -> emittedArticles.add(entry.emittedKey(position)) }
|
rawResults.forEach { (position, entry) -> emittedArticles.add(entry.emittedKey(position)) }
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ class IndexEntryPagingSource(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IndexEntry.emittedKey(dictPosition: Int) =
|
private fun IndexEntry.emittedKey(dictPosition: Int) =
|
||||||
EmittedKey(dictPosition, originalWord, offset.value, length.value)
|
EmittedKey(dictPosition, word, offset.value)
|
||||||
|
|
||||||
override fun getRefreshKey(state: PagingState<TailKey, IndexEntry>): TailKey? {
|
override fun getRefreshKey(state: PagingState<TailKey, IndexEntry>): TailKey? {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ fun SearchResultsList(
|
|||||||
) {
|
) {
|
||||||
items(
|
items(
|
||||||
count = results.itemCount,
|
count = results.itemCount,
|
||||||
|
key = results.itemKey { "${it.dictionaryPath}:${it.offset.value}:${it.word}" },
|
||||||
contentType = results.itemContentType { "search_result" }
|
contentType = results.itemContentType { "search_result" }
|
||||||
) { index ->
|
) { index ->
|
||||||
results[index]?.let { entry ->
|
results[index]?.let { entry ->
|
||||||
|
|||||||
Reference in New Issue
Block a user