From 832a74f9c2390d877af21fb3aac76b96c804a548 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 8 Jun 2026 10:35:46 +0900 Subject: [PATCH] search: add `jadbFilterWordIds` --- lib/search.dart | 6 +++++- lib/search/word_search/word_search.dart | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/search.dart b/lib/search.dart index 8a44777..cb152e4 100644 --- a/lib/search.dart +++ b/lib/search.dart @@ -44,7 +44,11 @@ extension JaDBConnection on DatabaseExecutor { pageSize: pageSize, ); - /// + /// Filter a list of word IDs, and return the ones that are listed in the word dictionary. + Future> jadbFilterWordIds(Iterable ids) => + filterWordIdsWithDbConnection(this, ids); + + /// Get a word by its ID. Returns null if no result is found for the given ID. Future jadbGetWordById(int id) => getWordByIdWithDbConnection(this, id); diff --git a/lib/search/word_search/word_search.dart b/lib/search/word_search/word_search.dart index 19f328c..fa7b5a9 100644 --- a/lib/search/word_search/word_search.dart +++ b/lib/search/word_search/word_search.dart @@ -96,6 +96,24 @@ Future searchWordCountWithDbConnection( return entryIdCount; } +Future> filterWordIdsWithDbConnection( + DatabaseExecutor connection, + Iterable ids, +) async { + if (ids.isEmpty) { + return {}; + } + + final Set filteredIds = await connection + .rawQuery( + 'SELECT "entryId" FROM "${JMdictTableNames.entry}" WHERE "entryId" IN (${ids.map((_) => '?').join(',')})', + ids.toList(), + ) + .then((rows) => rows.map((row) => row['entryId'] as int).toSet()); + + return filteredIds; +} + /// Fetches a single word by its entry ID, returning null if not found. Future getWordByIdWithDbConnection( DatabaseExecutor connection,