🔧 Fixes

This commit is contained in:
2021-12-31 15:34:27 -08:00
parent 7a92c1fddf
commit 486ac7b80b
2 changed files with 22 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import {
throttleAdapterEnhancer, throttleAdapterEnhancer,
} from "axios-extensions"; } from "axios-extensions";
import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils"; import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils";
import { isNil } from "lodash";
const CV_BASE_URL = "https://comicvine.gamespot.com/api/"; const CV_BASE_URL = "https://comicvine.gamespot.com/api/";
console.log("KEYYYYYYYY", process.env.COMICVINE_API_KEY); console.log("KEYYYYYYYY", process.env.COMICVINE_API_KEY);
@@ -157,6 +158,7 @@ export default class ComicVineService extends Service {
searchParams: { searchParams: {
searchTerms: { searchTerms: {
name: string; name: string;
subtitle?: string;
number: string; number: string;
year: string; year: string;
}; };
@@ -165,7 +167,9 @@ export default class ComicVineService extends Service {
rawFileDetails: object; rawFileDetails: object;
}> }>
) => { ) => {
console.log("scorer", ctx.params.scorerConfiguration);
const results: any = []; const results: any = [];
let subtitleFilter = "";
const volumes = await this.fetchVolumesFromCV( const volumes = await this.fetchVolumesFromCV(
ctx.params, ctx.params,
results, results,
@@ -182,8 +186,11 @@ export default class ComicVineService extends Service {
} }
volumeIdString += `${volumeId}|`; volumeIdString += `${volumeId}|`;
}); });
const issueYear = parseInt(ctx.params.scorerConfiguration.searchParams.searchTerms.year, 10); if(!isNil(ctx.params.scorerConfiguration.searchParams.searchTerms.subtitle)) {
subtitleFilter = `name:${ctx.params.scorerConfiguration.searchParams.searchTerms.subtitle}`;
}
// 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015 // 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015
const issueYear = parseInt(ctx.params.scorerConfiguration.searchParams.searchTerms.year, 10);
const coverDateFilter = `cover_date:${issueYear - 1}-01-01|${issueYear + 1}-12-31`; const coverDateFilter = `cover_date:${issueYear - 1}-01-01|${issueYear + 1}-12-31`;
const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.searchTerms.number},${volumeIdString},${coverDateFilter}`; const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.searchTerms.number},${volumeIdString},${coverDateFilter}`;
console.log(filterString); console.log(filterString);

View File

@@ -89,7 +89,6 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
// Iterate over volumes, checking to see: // Iterate over volumes, checking to see:
// 1. If the detected year of the issue falls in the range (end_year >= {detected year for issue} >= start_year ) // 1. If the detected year of the issue falls in the range (end_year >= {detected year for issue} >= start_year )
// 2. If there is a strong string comparison between the volume name and the issue name ?? // 2. If there is a strong string comparison between the volume name and the issue name ??
console.log(volumes.length);
const issueNumber = parseInt( const issueNumber = parseInt(
scorerConfiguration.searchParams.searchTerms.number, scorerConfiguration.searchParams.searchTerms.number,
10 10
@@ -108,25 +107,35 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
const lastIssueNumber = !isNil(volume.last_issue) const lastIssueNumber = !isNil(volume.last_issue)
? parseInt(volume.last_issue.issue_number, 10) ? parseInt(volume.last_issue.issue_number, 10)
: null; : null;
const issueNameMatchScore = stringSimilarity.compareTwoStrings( let issueNameMatchScore = stringSimilarity.compareTwoStrings(
scorerConfiguration.searchParams.searchTerms.name, scorerConfiguration.searchParams.searchTerms.name,
volume.name volume.name
); );
// 1. If issue year starts after the candidate volume's start year or is the same year, +2 to volumeMatchScore // 1. If there is a subtitle in the candidate volume's name, add it to the issueNameMatchScore
// If not, move on.
let subtitleMatchScore = 0;
if(!isNil(scorerConfiguration.searchParams.searchTerms.subtitle)) {
subtitleMatchScore = stringSimilarity.compareTwoStrings(scorerConfiguration.searchParams.searchTerms.subtitle, volume.name);
console.log(scorerConfiguration.searchParams.searchTerms.subtitle, subtitleMatchScore);
if(subtitleMatchScore > 0.1) {
issueNameMatchScore += subtitleMatchScore;
}
}
// 2. If issue year starts after the candidate volume's start year or is the same year, +2 to volumeMatchScore
if (!isNil(volumeStartYear)) { if (!isNil(volumeStartYear)) {
if (isSameYear(issueYear, volumeStartYear) || if (isSameYear(issueYear, volumeStartYear) ||
isAfter(issueYear, volumeStartYear)) { isAfter(issueYear, volumeStartYear)) {
volumeMatchScore += 2; volumeMatchScore += 2;
} }
} }
// 2. If issue number falls in the range of candidate volume's first issue # and last issue #, +3 to volumeMatchScore // 3. If issue number falls in the range of candidate volume's first issue # and last issue #, +3 to volumeMatchScore
if(!isNil(firstIssueNumber) && !isNil(lastIssueNumber)) { if(!isNil(firstIssueNumber) && !isNil(lastIssueNumber)) {
if(firstIssueNumber <= issueNumber || issueNumber <= lastIssueNumber) { if(firstIssueNumber <= issueNumber || issueNumber <= lastIssueNumber) {
volumeMatchScore += 3; volumeMatchScore += 3;
} }
} }
if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) { if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) {
console.log("VOLUME SCORE: ", volumeMatchScore); console.log("VOLUME SCORE: ", issueNameMatchScore);
return volume.id; return volume.id;
} }
}); });