support comma (,) delimiter when searching library

This commit is contained in:
Cuong-Tran 2024-11-07 14:48:32 +07:00
parent c84fb61084
commit c801a8c7d1
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 38 additions and 39 deletions

View file

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import eu.kanade.tachiyomi.source.getNameForMangaInfo
import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.model.Source
import tachiyomi.domain.source.service.SourceManager import tachiyomi.domain.source.service.SourceManager
@ -19,42 +18,42 @@ data class LibraryItem(
// KMK <-- // KMK <--
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
) { ) {
/** // /**
* Checks if a query matches the manga // * Checks if a query matches the manga
* // *
* @param constraint the query to check. // * @param constraint the query to check.
* @return true if the manga matches the query, false otherwise. // * @return true if the manga matches the query, false otherwise.
*/ // */
fun matches(constraint: String): Boolean { // fun matches(constraint: String): Boolean {
val sourceName by lazy { sourceManager.getOrStub(libraryManga.manga.source).getNameForMangaInfo() } // val sourceName by lazy { sourceManager.getOrStub(libraryManga.manga.source).getNameForMangaInfo() }
return libraryManga.manga.title.contains(constraint, true) || // return libraryManga.manga.title.contains(constraint, true) ||
(libraryManga.manga.author?.contains(constraint, true) ?: false) || // (libraryManga.manga.author?.contains(constraint, true) ?: false) ||
(libraryManga.manga.artist?.contains(constraint, true) ?: false) || // (libraryManga.manga.artist?.contains(constraint, true) ?: false) ||
(libraryManga.manga.description?.contains(constraint, true) ?: false) || // (libraryManga.manga.description?.contains(constraint, true) ?: false) ||
constraint.split(",").map { it.trim() }.all { subconstraint -> // constraint.split(",").map { it.trim() }.all { subconstraint ->
checkNegatableConstraint(subconstraint) { // checkNegatableConstraint(subconstraint) {
sourceName.contains(it, true) || // sourceName.contains(it, true) ||
(libraryManga.manga.genre?.any { genre -> genre.equals(it, true) } ?: false) // (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, // * 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. // * 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 constraint the argument to the predicate. Inverts the predicate if it starts with '-'.
* @param predicate the check to be run against the constraint. // * @param predicate the check to be run against the constraint.
* @return !predicate(x) if constraint = "-x", otherwise predicate(constraint) // * @return !predicate(x) if constraint = "-x", otherwise predicate(constraint)
*/ // */
private fun checkNegatableConstraint( // private fun checkNegatableConstraint(
constraint: String, // constraint: String,
predicate: (String) -> Boolean, // predicate: (String) -> Boolean,
): Boolean { // ): Boolean {
return if (constraint.startsWith("-")) { // return if (constraint.startsWith("-")) {
!predicate(constraint.substringAfter("-").trimStart()) // !predicate(constraint.substringAfter("-").trimStart())
} else { // } else {
predicate(constraint) // predicate(constraint)
} // }
} // }
} }

View file

@ -191,7 +191,7 @@ class SearchEngine {
else -> flushed else -> flushed
} }
namespace = Namespace(flushed, null) namespace = Namespace(flushed, null)
} else if (char == ' ' && !inQuotes) { } else if (arrayOf(' ', ',').contains(char) && !inQuotes) {
flushAll() flushAll()
} else { } else {
queuedRawText.append(char) queuedRawText.append(char)