From 52a686ac296d2d4e2b356dbe5b91d9878599a5ce Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 22 May 2025 16:57:05 +0200 Subject: [PATCH] lib/search/word: fix english sql query --- lib/search/word_search/entry_id_query.dart | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/search/word_search/entry_id_query.dart b/lib/search/word_search/entry_id_query.dart index 2340aaa..4c61e70 100644 --- a/lib/search/word_search/entry_id_query.dart +++ b/lib/search/word_search/entry_id_query.dart @@ -133,13 +133,22 @@ Future> fetchEntryIds( break; case SearchMode.English: - entryIds = (await connection.query( - JMdictTableNames.senseGlossary, - columns: ['entryId'], - where: 'english LIKE ?', - whereArgs: ['%$word%'], - limit: pageSize, - offset: offset, + entryIds = (await connection.rawQuery( + ''' + SELECT DISTINCT + "${JMdictTableNames.sense}"."entryId" + FROM "${JMdictTableNames.senseGlossary}" + JOIN "${JMdictTableNames.sense}" USING ("senseId") + WHERE "${JMdictTableNames.senseGlossary}"."phrase" LIKE ? + LIMIT ? + OFFSET ? + ''' + .trim(), + [ + '%$word%', + pageSize, + offset, + ], )) .map((row) => ScoredEntryId( row['entryId'] as int, @@ -200,13 +209,19 @@ Future fetchEntryIdCount( break; case SearchMode.English: - entryIdCount = (await connection.query( - JMdictTableNames.senseGlossary, - columns: ['COUNT(DISTINCT entryId)'], - where: 'english LIKE ?', - whereArgs: ['%$word%'], + entryIdCount = (await connection.rawQuery( + ''' + SELECT COUNT(DISTINCT "${JMdictTableNames.sense}"."entryId") AS "count" + FROM "${JMdictTableNames.senseGlossary}" + JOIN "${JMdictTableNames.sense}" USING ("senseId") + WHERE "${JMdictTableNames.senseGlossary}"."phrase" LIKE ? + ''' + .trim(), + [ + '%$word%', + ], )) - .firstOrNull?['COUNT(DISTINCT entryId)'] as int?; + .firstOrNull?['count'] as int?; break; case SearchMode.MixedKana: