From 0d712e43654f1259f29b4ef888ce6a8bb1607002 Mon Sep 17 00:00:00 2001 From: MajorTanya <39014446+MajorTanya@users.noreply.github.com> Date: Tue, 3 Feb 2026 10:54:22 +0100 Subject: [PATCH] Add "src:" prefix to search by source ID (mihonapp/mihon#2927) Allows users to search for the exact source ID in their library. Similar to the Browse > Migrate screen, but filtered in the Library, where users can take all the usual actions. Could be used in the future to change the search behaviour of tapping the source name in the title info view to search by the ID with this prefix. (cherry picked from commit 4e4bdffdf38043418685ab42b177c8476842c83c) --- CHANGELOG.md | 1 + .../tachiyomi/ui/library/LibraryItem.kt | 47 ++++++++++--------- .../ui/library/LibraryScreenModel.kt | 6 ++- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 992de7e76..eb5146724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Automatically remove downloads on Suwayomi after reading, configurable via extension settings ([@cpiber](https://github.com/cpiber)) ([#2673](https://github.com/mihonapp/mihon/pull/2673)) - Display author & artist name in MAL search results ([@MajorTanya](https://github.com/MajorTanya)) ([#2833](https://github.com/mihonapp/mihon/pull/2833)) - Add filter options to Updates tab ([@MajorTanya](https://github.com/MajorTanya)) ([#2851](https://github.com/mihonapp/mihon/pull/2851)) +- Add `src:` prefix to search the library by source ID ([@MajorTanya](https://github.com/MajorTanya)) ([#2927](https://github.com/mihonapp/mihon/pull/2927)) ### Improved - Minimize memory usage by reducing in-memory cover cache size ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2266](https://github.com/mihonapp/mihon/pull/2266)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 0f04a8c7c..2f2fcee8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -20,28 +20,31 @@ data class LibraryItem( ) { val id: Long = libraryManga.id - // /** - // * 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() } - // if (constraint.startsWith("id:", true)) { - // return id == constraint.substringAfter("id:").toLongOrNull() - // } - // 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 source = sourceManager.getOrStub(libraryManga.manga.source) +// val sourceName by lazy { source.getNameForMangaInfo() } +// if (constraint.startsWith("id:", true)) { +// return id == constraint.substringAfter("id:").toLongOrNull() +// } else if (constraint.startsWith("src:", true)) { +// return source.id == constraint.substringAfter("src:").toLongOrNull() +// } +// 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, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt index 05f0fe85a..fec525e7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt @@ -1176,10 +1176,12 @@ class LibraryScreenModel( unfiltered.asFlow().cancellable().filter { item -> val mangaId = item.libraryManga.manga.id if (query.startsWith("id:", true)) { - val id = query.substringAfter("id:").toLongOrNull() - return@filter mangaId == id + return@filter mangaId == query.substringAfter("id:").toLongOrNull() } val sourceId = item.libraryManga.manga.source + if (query.startsWith("src:", true)) { + return@filter sourceId == query.substringAfter("src:").toLongOrNull() + } if (isMetadataSource(sourceId) && mangaWithMetaIds.binarySearch(mangaId) >= 0) { val tags = getSearchTags.await(mangaId) val titles = getSearchTitles.await(mangaId)