From 7247af19cbbe636a476228debf6ad3c3c7a70255 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 7 Jul 2025 13:27:50 +0200 Subject: [PATCH] word_search: always order exact matches first --- lib/search/word_search/entry_id_query.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/search/word_search/entry_id_query.dart b/lib/search/word_search/entry_id_query.dart index 1dabd31..10c12de 100644 --- a/lib/search/word_search/entry_id_query.dart +++ b/lib/search/word_search/entry_id_query.dart @@ -53,7 +53,7 @@ String _filterFTSSensitiveCharacters(String word) { SELECT DISTINCT "${tableName}"."entryId", 100 - + (("${tableName}FTS"."reading" = ?) * 50) + + (("${tableName}FTS"."reading" = ?) * 10000) + "JMdict_EntryScore"."score" AS "score" FROM "${tableName}FTS" @@ -61,8 +61,6 @@ String _filterFTSSensitiveCharacters(String word) { JOIN "JMdict_EntryScore" USING ("elementId") WHERE "${tableName}FTS"."reading" MATCH ? || '*' AND "JMdict_EntryScore"."type" = '${tableName == JMdictTableNames.kanjiElement ? 'k' : 'r'}' - ORDER BY - "JMdict_EntryScore"."score" DESC ${!countOnly ? 'LIMIT ?' : ''} ), non_fts_results AS ( @@ -76,9 +74,6 @@ String _filterFTSSensitiveCharacters(String word) { WHERE "reading" LIKE '%' || ? || '%' AND "${tableName}"."entryId" NOT IN (SELECT "entryId" FROM "fts_results") AND "JMdict_EntryScore"."type" = '${tableName == JMdictTableNames.kanjiElement ? 'k' : 'r'}' - ORDER BY - "JMdict_EntryScore"."score" DESC, - "${tableName}"."entryId" ASC ${!countOnly ? 'LIMIT ?' : ''} ) @@ -89,6 +84,9 @@ String _filterFTSSensitiveCharacters(String word) { SELECT * FROM non_fts_results ) GROUP BY "entryId" + ORDER BY + "score" DESC, + "entryId" ASC ''' .trim(), [