make fuzzy metadata search happen after all other database operations have settled.

This commit is contained in:
Alexandra
2025-05-29 16:53:31 -06:00
parent d7e1822843
commit 85b57e6c39
3 changed files with 8 additions and 6 deletions

View File

@@ -66,7 +66,7 @@ export default class MetadataSearch {
this.platformMap = JSON.parse(readFileSync(mapFilePath, "utf8")); this.platformMap = JSON.parse(readFileSync(mapFilePath, "utf8"));
if (this.accessToken) { if (this.accessToken) {
this.authorized = true; this.authorized = true;
this.syncAllMetadata(); this.matchAllMetadata();
return; return;
} }
} }
@@ -110,7 +110,7 @@ export default class MetadataSearch {
} }
} }
async matchAllMetadata() { async matchAllMetadata(fuzzy = false) {
let games = await File.findAndCountAll({ let games = await File.findAndCountAll({
where: { where: {
nongame: false, nongame: false,
@@ -154,14 +154,15 @@ export default class MetadataSearch {
await game.save(); await game.save();
await md.save(); await md.save();
found++; found++;
} else { } else if (fuzzy) {
//this is much slower and should only be used if the faster full text search can't find it. //this is much slower and should only be used if the faster full text search can't find it.
let metadata = Metadata.fuzzySearchByText( let metadata = await Metadata.fuzzySearchByText(
this.normalizeName(game.filename), this.normalizeName(game.filename),
0.6, 0.6,
game.category game.category
); );
if (metadata) { if (metadata.length) {
let md = await Metadata.findByPk(metadata[0].id);
await game.setDetails(md); await game.setDetails(md);
await md.addFile(game); await md.addFile(game);
await game.save(); await game.save();

View File

@@ -114,7 +114,7 @@ export default function (sequelize) {
} }
const query = ` const query = `
SELECT id FROM "Metadata" SELECT id FROM "Metadata"
WHERE SIMILARITY(title, $1) > $2 OR WHERE SIMILARITY(alternatetitles, $1) > $2 WHERE SIMILARITY(title, $1) > $2 OR SIMILARITY(alternatetitles, $1) > $2
${platformClause} ${platformClause}
ORDER BY length(title) ${limitClause} ORDER BY length(title) ${limitClause}
`; `;

View File

@@ -87,6 +87,7 @@ async function getFilesJob() {
await metadataSearch.syncAllMetadata(); await metadataSearch.syncAllMetadata();
} }
optimizeDatabaseKws(); optimizeDatabaseKws();
metadataSearch.matchAllMetadata(true)
} }
function buildOptions(page, options) { function buildOptions(page, options) {