From 1068bdc8dc51182dc2742a3def6c8738754a1927 Mon Sep 17 00:00:00 2001 From: MatchaSoba <76941874+MatchaSoba@users.noreply.github.com> Date: Sun, 17 Jul 2022 22:19:38 +0800 Subject: [PATCH] Koushoku: Improve query building (#12612) --- src/en/koushoku/build.gradle | 2 +- .../extension/en/koushoku/Koushoku.kt | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/en/koushoku/build.gradle b/src/en/koushoku/build.gradle index cdd28f55b..0b2719a11 100644 --- a/src/en/koushoku/build.gradle +++ b/src/en/koushoku/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Koushoku' pkgNameSuffix = 'en.koushoku' extClass = '.Koushoku' - extVersionCode = 5 + extVersionCode = 6 isNsfw = true } diff --git a/src/en/koushoku/src/eu/kanade/tachiyomi/extension/en/koushoku/Koushoku.kt b/src/en/koushoku/src/eu/kanade/tachiyomi/extension/en/koushoku/Koushoku.kt index 460dbadf8..7d1706931 100644 --- a/src/en/koushoku/src/eu/kanade/tachiyomi/extension/en/koushoku/Koushoku.kt +++ b/src/en/koushoku/src/eu/kanade/tachiyomi/extension/en/koushoku/Koushoku.kt @@ -80,22 +80,31 @@ class Koushoku : ParsedHttpSource() { val filterList = if (filters.isEmpty()) getFilterList() else filters filterList.findInstance()?.addQueryParameter(url) url.addQueryParameter("q", buildAdvQuery(query, filterList)) - println(url) return GET(url.toString(), headers) } private fun buildAdvQuery(query: String, filterList: FilterList): String { - val title = "title*:$query" + val title = if (query.isNotBlank()) "title*:$query " else "" val filters: List = filterList.filterIsInstance().map { filter -> + if (filter.state.isBlank()) return@map "" val included = mutableListOf() val excluded = mutableListOf() val name = if (filter.name.lowercase().contentEquals("tags")) "tag" else filter.name.lowercase() filter.state.split(",").map(String::trim).filterNot(String::isBlank).forEach { entry -> - if (entry.startsWith("-")) excluded.add(entry) else included.add(entry) + if (entry.startsWith("-")) { + excluded.add(entry.slice(1 until entry.length)) + } else { + included.add(entry) + } + } + buildString { + if (included.isNotEmpty()) append("$name*:${included.joinToString(",")} ") + if (excluded.isNotEmpty()) append("-$name*:${excluded.joinToString(",")}") } - "$name*:${included.joinToString(",")} -$name*:${excluded.joinToString(",")}" } - return "$title ${filters.joinToString(" ")}" + return "$title${ + filters.filterNot(String::isBlank).joinToString(" ", transform = String::trim) + }" } override fun searchMangaSelector() = latestUpdatesSelector()