mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Refactored search functionality according to the new wrapper
This commit is contained in:
parent
7a6447c5da
commit
75adf8185a
@ -100,9 +100,8 @@ play {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
androidTestImplementation(Libs.leakcanary_android_instrumentation)
|
androidTestImplementation(Libs.leakcanary_android_instrumentation)
|
||||||
|
implementation(files("/home/hp-pc03/Desktop/lib-debug.aar"))
|
||||||
api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
||||||
implementation("com.getkeepsafe.relinker:relinker:1.4.5")
|
|
||||||
implementation(files("C:\\Users\\aades\\OneDrive\\Documents/lib-debug.aar"))
|
|
||||||
}
|
}
|
||||||
task("generateVersionCodeAndName") {
|
task("generateVersionCodeAndName") {
|
||||||
val file = File("VERSION_INFO")
|
val file = File("VERSION_INFO")
|
||||||
|
@ -65,10 +65,9 @@ dependencies {
|
|||||||
// } else {
|
// } else {
|
||||||
// api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
// api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
||||||
// }
|
// }
|
||||||
|
implementation(files("/home/hp-pc03/Desktop/lib-debug.aar"))
|
||||||
api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
|
||||||
implementation("com.getkeepsafe.relinker:relinker:1.4.5")
|
implementation("com.getkeepsafe.relinker:relinker:1.4.5")
|
||||||
implementation(files("C:\\Users\\aades\\OneDrive\\Documents/lib-debug.aar"))
|
api(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
||||||
|
|
||||||
// Document File
|
// Document File
|
||||||
implementation(Libs.select_folder_document_file)
|
implementation(Libs.select_folder_document_file)
|
||||||
|
@ -137,7 +137,7 @@ class ZimFileReader constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun searchSuggestions(prefix: String): Search =
|
fun searchSuggestions(prefix: String): Search =
|
||||||
searcher.search(Query(prefix).setQuery(prefix))
|
searcher.search(Query(prefix))
|
||||||
|
|
||||||
fun getNextSuggestion(suggestionSearch: SuggestionSearch?): List<SearchSuggestion> {
|
fun getNextSuggestion(suggestionSearch: SuggestionSearch?): List<SearchSuggestion> {
|
||||||
val suggestionList = mutableListOf<SearchSuggestion>()
|
val suggestionList = mutableListOf<SearchSuggestion>()
|
||||||
|
@ -24,7 +24,6 @@ import kotlinx.coroutines.yield
|
|||||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||||
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem
|
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem
|
||||||
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem.ZimSearchResultListItem
|
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem.ZimSearchResultListItem
|
||||||
import org.kiwix.libzim.SuggestionSearch
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
interface SearchResultGenerator {
|
interface SearchResultGenerator {
|
||||||
@ -53,32 +52,12 @@ class ZimSearchResultGenerator @Inject constructor() : SearchResultGenerator {
|
|||||||
val suggestionList = mutableListOf<ZimSearchResultListItem>()
|
val suggestionList = mutableListOf<ZimSearchResultListItem>()
|
||||||
val suggestionIterator =
|
val suggestionIterator =
|
||||||
this?.getResults(0, this.estimatedMatches.toInt())
|
this?.getResults(0, this.estimatedMatches.toInt())
|
||||||
if (suggestionIterator != null) {
|
suggestionIterator?.let {
|
||||||
while (suggestionIterator.hasNext()) {
|
while (it.hasNext()) {
|
||||||
suggestionList.add(ZimSearchResultListItem(suggestionIterator.title))
|
val entry = it.next()
|
||||||
|
suggestionList.add(ZimSearchResultListItem(entry.title))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return@run suggestionList
|
return@run suggestionList
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun suggestionResults(
|
|
||||||
reader: ZimFileReader?,
|
|
||||||
suggestionSearch: SuggestionSearch?
|
|
||||||
) = createList {
|
|
||||||
yield()
|
|
||||||
reader?.getNextSuggestion(suggestionSearch)
|
|
||||||
?.let {
|
|
||||||
ZimSearchResultListItem(it[0].title)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.distinct()
|
|
||||||
.toList()
|
|
||||||
|
|
||||||
private suspend fun <T> createList(readSearchResult: suspend () -> T?): List<T> {
|
|
||||||
return mutableListOf<T>().apply {
|
|
||||||
while (true) {
|
|
||||||
readSearchResult()?.let(::add) ?: break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user