support comma (,) delimiter when searching library
This commit is contained in:
parent
c84fb61084
commit
c801a8c7d1
2 changed files with 38 additions and 39 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import eu.kanade.tachiyomi.source.getNameForMangaInfo
|
||||
import tachiyomi.domain.library.model.LibraryManga
|
||||
import tachiyomi.domain.source.model.Source
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
|
|
@ -19,42 +18,42 @@ data class LibraryItem(
|
|||
// KMK <--
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
) {
|
||||
/**
|
||||
* Checks if a query matches the manga
|
||||
*
|
||||
* @param constraint the query to check.
|
||||
* @return true if the manga matches the query, false otherwise.
|
||||
*/
|
||||
fun matches(constraint: String): Boolean {
|
||||
val sourceName by lazy { sourceManager.getOrStub(libraryManga.manga.source).getNameForMangaInfo() }
|
||||
return libraryManga.manga.title.contains(constraint, true) ||
|
||||
(libraryManga.manga.author?.contains(constraint, true) ?: false) ||
|
||||
(libraryManga.manga.artist?.contains(constraint, true) ?: false) ||
|
||||
(libraryManga.manga.description?.contains(constraint, true) ?: false) ||
|
||||
constraint.split(",").map { it.trim() }.all { subconstraint ->
|
||||
checkNegatableConstraint(subconstraint) {
|
||||
sourceName.contains(it, true) ||
|
||||
(libraryManga.manga.genre?.any { genre -> genre.equals(it, true) } ?: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Checks if a query matches the manga
|
||||
// *
|
||||
// * @param constraint the query to check.
|
||||
// * @return true if the manga matches the query, false otherwise.
|
||||
// */
|
||||
// fun matches(constraint: String): Boolean {
|
||||
// val sourceName by lazy { sourceManager.getOrStub(libraryManga.manga.source).getNameForMangaInfo() }
|
||||
// return libraryManga.manga.title.contains(constraint, true) ||
|
||||
// (libraryManga.manga.author?.contains(constraint, true) ?: false) ||
|
||||
// (libraryManga.manga.artist?.contains(constraint, true) ?: false) ||
|
||||
// (libraryManga.manga.description?.contains(constraint, true) ?: false) ||
|
||||
// constraint.split(",").map { it.trim() }.all { subconstraint ->
|
||||
// checkNegatableConstraint(subconstraint) {
|
||||
// sourceName.contains(it, true) ||
|
||||
// (libraryManga.manga.genre?.any { genre -> genre.equals(it, true) } ?: false)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Checks a predicate on a negatable constraint. If the constraint starts with a minus character,
|
||||
* the minus is stripped and the result of the predicate is inverted.
|
||||
*
|
||||
* @param constraint the argument to the predicate. Inverts the predicate if it starts with '-'.
|
||||
* @param predicate the check to be run against the constraint.
|
||||
* @return !predicate(x) if constraint = "-x", otherwise predicate(constraint)
|
||||
*/
|
||||
private fun checkNegatableConstraint(
|
||||
constraint: String,
|
||||
predicate: (String) -> Boolean,
|
||||
): Boolean {
|
||||
return if (constraint.startsWith("-")) {
|
||||
!predicate(constraint.substringAfter("-").trimStart())
|
||||
} else {
|
||||
predicate(constraint)
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Checks a predicate on a negatable constraint. If the constraint starts with a minus character,
|
||||
// * the minus is stripped and the result of the predicate is inverted.
|
||||
// *
|
||||
// * @param constraint the argument to the predicate. Inverts the predicate if it starts with '-'.
|
||||
// * @param predicate the check to be run against the constraint.
|
||||
// * @return !predicate(x) if constraint = "-x", otherwise predicate(constraint)
|
||||
// */
|
||||
// private fun checkNegatableConstraint(
|
||||
// constraint: String,
|
||||
// predicate: (String) -> Boolean,
|
||||
// ): Boolean {
|
||||
// return if (constraint.startsWith("-")) {
|
||||
// !predicate(constraint.substringAfter("-").trimStart())
|
||||
// } else {
|
||||
// predicate(constraint)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class SearchEngine {
|
|||
else -> flushed
|
||||
}
|
||||
namespace = Namespace(flushed, null)
|
||||
} else if (char == ' ' && !inQuotes) {
|
||||
} else if (arrayOf(' ', ',').contains(char) && !inQuotes) {
|
||||
flushAll()
|
||||
} else {
|
||||
queuedRawText.append(char)
|
||||
|
|
|
|||
Loading…
Reference in a new issue