Koushoku: Improve query building (#12612)
This commit is contained in:
parent
3ffb75cee3
commit
1068bdc8dc
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'Koushoku'
|
extName = 'Koushoku'
|
||||||
pkgNameSuffix = 'en.koushoku'
|
pkgNameSuffix = 'en.koushoku'
|
||||||
extClass = '.Koushoku'
|
extClass = '.Koushoku'
|
||||||
extVersionCode = 5
|
extVersionCode = 6
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,22 +80,31 @@ class Koushoku : ParsedHttpSource() {
|
||||||
val filterList = if (filters.isEmpty()) getFilterList() else filters
|
val filterList = if (filters.isEmpty()) getFilterList() else filters
|
||||||
filterList.findInstance<SortFilter>()?.addQueryParameter(url)
|
filterList.findInstance<SortFilter>()?.addQueryParameter(url)
|
||||||
url.addQueryParameter("q", buildAdvQuery(query, filterList))
|
url.addQueryParameter("q", buildAdvQuery(query, filterList))
|
||||||
println(url)
|
|
||||||
return GET(url.toString(), headers)
|
return GET(url.toString(), headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAdvQuery(query: String, filterList: FilterList): String {
|
private fun buildAdvQuery(query: String, filterList: FilterList): String {
|
||||||
val title = "title*:$query"
|
val title = if (query.isNotBlank()) "title*:$query " else ""
|
||||||
val filters: List<String> = filterList.filterIsInstance<Filter.Text>().map { filter ->
|
val filters: List<String> = filterList.filterIsInstance<Filter.Text>().map { filter ->
|
||||||
|
if (filter.state.isBlank()) return@map ""
|
||||||
val included = mutableListOf<String>()
|
val included = mutableListOf<String>()
|
||||||
val excluded = mutableListOf<String>()
|
val excluded = mutableListOf<String>()
|
||||||
val name = if (filter.name.lowercase().contentEquals("tags")) "tag" else filter.name.lowercase()
|
val name = if (filter.name.lowercase().contentEquals("tags")) "tag" else filter.name.lowercase()
|
||||||
filter.state.split(",").map(String::trim).filterNot(String::isBlank).forEach { entry ->
|
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()
|
override fun searchMangaSelector() = latestUpdatesSelector()
|
||||||
|
|
Loading…
Reference in New Issue