migrations: combine score tables

This commit is contained in:
2025-05-23 15:27:56 +02:00
parent 03a8e11d91
commit f819280268
3 changed files with 141 additions and 157 deletions

View File

@@ -41,28 +41,31 @@ SearchMode _determineSearchMode(String word) {
"${tableName}FTS"."entryId",
100
+ (("${tableName}FTS"."reading" = ?) * 50)
+ "${tableName}Score"."score"
+ "JMdict_EntryScore"."score"
AS "score"
FROM "${tableName}FTS"
JOIN "${tableName}" USING ("entryId", "reading")
JOIN "${tableName}Score" USING ("entryId", "reading")
JOIN "JMdict_EntryScore" USING ("entryId", "reading")
WHERE "${tableName}FTS"."reading" MATCH ? || '*'
ORDER BY "score" DESC
AND "JMdict_EntryScore"."type" = '${tableName == JMdictTableNames.kanjiElement ? 'kanji' : 'reading'}'
ORDER BY
"JMdict_EntryScore"."score" DESC
${!countOnly ? 'LIMIT ?' : ''}
),
non_fts_results AS (
SELECT DISTINCT
"entryId",
"${tableName}"."entryId",
50
+ "${tableName}Score"."score"
+ "JMdict_EntryScore"."score"
AS "score"
FROM "${tableName}"
JOIN "${tableName}Score" USING ("entryId", "reading")
JOIN "JMdict_EntryScore" USING ("entryId", "reading")
WHERE "reading" LIKE '%' || ? || '%'
AND "entryId" NOT IN (SELECT "entryId" FROM "fts_results")
AND "JMdict_EntryScore"."type" = '${tableName == JMdictTableNames.kanjiElement ? 'kanji' : 'reading'}'
ORDER BY
"score" DESC,
"entryId" ASC
"JMdict_EntryScore"."score" DESC,
"${tableName}"."entryId" ASC
${!countOnly ? 'LIMIT ?' : ''}
)