From 2783cee02e3e29bbf8abbe6ca71be8af54ce3e85 Mon Sep 17 00:00:00 2001 From: MajorTanya <39014446+MajorTanya@users.noreply.github.com> Date: Thu, 13 Mar 2025 10:36:34 +0100 Subject: [PATCH] Add prefix search to search by internal DB ID (mihonapp/mihon#1856) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prefix searches entries in the library based on the ID in the database. It is a niche feature but could be very helpful in certain situations, such as a corrupted cover causing a crash that just shows "🚨 Failed - MangaCover(mangaId=2245, sourceId=1, isMangaFavorite=true, url=, lastModified=0)". With this prefix search it is possible to find the entry in question without much hassle. Notably, the database includes literally anything Mihon has ever seen from extension and such, even if they weren't added to the collection. This means that IDs actually present in the collection are not expected to be purely sequential. For example, in my emulator, I had two entries in the collection but the assigned IDs were 5 and 56. (cherry picked from commit 05012de569130e131be92b71fbfc9308ea6c629c) --- CHANGELOG.md | 1 + .../eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05bc44391..c2b7d5f8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Add back support for drag-and-drop category reordering ([@cuong-tran](https://github.com/cuong-tran)) ([#1427](https://github.com/mihonapp/mihon/pull/1427)) - Add option to mark duplicate read chapters as read after library update or while reading ([@AntsyLich](https://github.com/AntsyLich)) ([#1785](https://github.com/mihonapp/mihon/pull/1785), [#1791](https://github.com/mihonapp/mihon/pull/1791), [#1870](https://github.com/mihonapp/mihon/pull/1870)) - Display staff information on Anilist tracker search results ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#1810](https://github.com/mihonapp/mihon/pull/1810)) +- Add `id:` prefix search to library to search by internal DB ID ([@MajorTanya](https://github.com/MajorTanya)) ([#1856](https://github.com/mihonapp/mihon/pull/1856)) ### Changed - Sliders UI 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 2bed5b784..996e4ff98 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 @@ -981,7 +981,7 @@ class LibraryScreenModel( } } - suspend fun filterLibrary(unfiltered: List, query: String?, loggedInTrackServices: Map): List { + private suspend fun filterLibrary(unfiltered: List, query: String?, loggedInTrackServices: Map): List { return if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) { // Prepare filter object val parsedQuery = searchEngine.parseQuery(query) @@ -997,6 +997,10 @@ class LibraryScreenModel( .associateBy { it.id } 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 + } val sourceId = item.libraryManga.manga.source if (isMetadataSource(sourceId) && mangaWithMetaIds.binarySearch(mangaId) >= 0) { val tags = getSearchTags.await(mangaId)