🔨 Fixes to searchmatchscorer
Some checks failed
Docker Image CI / build (push) Has been cancelled

This commit is contained in:
2026-04-14 07:11:18 -04:00
parent 2e31f6cf49
commit c604bd8e4d

View File

@@ -152,7 +152,7 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
}; };
const calculateLevenshteinDistance = async (match: any, rawFileDetails: any) => const calculateLevenshteinDistance = async (match: any, rawFileDetails: any) =>
new Promise((resolve, reject) => { new Promise((resolve) => {
https.get(match.image.small_url, (response: any) => { https.get(match.image.small_url, (response: any) => {
console.log(rawFileDetails.cover.filePath); console.log(rawFileDetails.cover.filePath);
const fileName = match.id + "_" + rawFileDetails.name + ".jpg"; const fileName = match.id + "_" + rawFileDetails.name + ".jpg";
@@ -166,39 +166,42 @@ const calculateLevenshteinDistance = async (match: any, rawFileDetails: any) =>
); );
const fileStream = response.pipe(file); const fileStream = response.pipe(file);
fileStream.on("finish", async () => { fileStream.on("finish", async () => {
// 1. hash of the cover image we have on hand try {
const coverFileName = rawFileDetails.cover.filePath // 1. hash of the cover image we have on hand
.split("/") const coverFileName = rawFileDetails.cover.filePath
.at(-1); .split("/")
const coverDirectory = rawFileDetails.containedIn .at(-1);
.split("/") const coverDirectory = rawFileDetails.containedIn
.at(-1); .split("/")
const hash1 = await imghash.hash( .at(-1);
path.resolve( const hash1 = await imghash.hash(
`${process.env.USERDATA_DIRECTORY}/covers/${coverDirectory}/${coverFileName}` path.resolve(
) `${process.env.USERDATA_DIRECTORY}/covers/${coverDirectory}/${coverFileName}`
); )
// 2. hash of the cover of the potential match );
const hash2 = await imghash.hash( // 2. hash of the cover of the potential match
path.resolve( const hash2 = await imghash.hash(
`${process.env.USERDATA_DIRECTORY}/temporary/${fileName}` path.resolve(
) `${process.env.USERDATA_DIRECTORY}/temporary/${fileName}`
); )
if (!isUndefined(hash1) && !isUndefined(hash2)) { );
const levenshteinDistance = leven(hash1, hash2); if (!isUndefined(hash1) && !isUndefined(hash2)) {
if (levenshteinDistance === 0) { const levenshteinDistance = leven(hash1, hash2);
match.score += 2; if (levenshteinDistance === 0) {
} else if ( match.score += 2;
levenshteinDistance > 0 && } else if (
levenshteinDistance <= 2 levenshteinDistance > 0 &&
) { levenshteinDistance <= 2
match.score += 1; ) {
} else { match.score += 1;
match.score -= 2; } else {
match.score -= 2;
}
} }
resolve(match); resolve(match);
} else { } catch (err) {
reject({ error: "Couldn't calculate hashes." }); console.warn(`Image hashing failed for ${fileName}, skipping score adjustment:`, err.message);
resolve(match);
} }
}); });
}); });