🔧 Fixed a conditional in search match scorer

This commit is contained in:
2022-01-02 12:47:15 -08:00
parent 486ac7b80b
commit ba31650543
2 changed files with 26 additions and 16 deletions

View File

@@ -8,8 +8,8 @@ import {
cacheAdapterEnhancer, cacheAdapterEnhancer,
throttleAdapterEnhancer, throttleAdapterEnhancer,
} from "axios-extensions"; } from "axios-extensions";
import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils";
import { isNil } from "lodash"; import { isNil } from "lodash";
import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils";
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);
@@ -128,7 +128,9 @@ export default class ComicVineService extends Service {
ctx.params.volumeURI + ctx.params.volumeURI +
"?api_key=" + "?api_key=" +
process.env.COMICVINE_API_KEY, process.env.COMICVINE_API_KEY,
params: ctx.params.data, params: {
format: "json",
},
headers: { Accept: "application/json" }, headers: { Accept: "application/json" },
}); });
const { data } = response; const { data } = response;
@@ -167,15 +169,15 @@ export default class ComicVineService extends Service {
rawFileDetails: object; rawFileDetails: object;
}> }>
) => { ) => {
console.log("scorer", ctx.params.scorerConfiguration); console.log("Searching against: ", ctx.params.scorerConfiguration.searchParams.searchTerms);
const results: any = []; const results: any = [];
let subtitleFilter = "";
const volumes = await this.fetchVolumesFromCV( const volumes = await this.fetchVolumesFromCV(
ctx.params, ctx.params,
results, results,
); );
// 1. Run the current batch of volumes through the matcher // 1. Run the current batch of volumes through the matcher
const potentialVolumeMatches = rankVolumes(volumes, ctx.params.scorerConfiguration); const potentialVolumeMatches = rankVolumes(volumes, ctx.params.scorerConfiguration);
// 2. Construct the filter string // 2. Construct the filter string
// 2a. volume: 1111|2222|3333 // 2a. volume: 1111|2222|3333
let volumeIdString = "volume:"; let volumeIdString = "volume:";
@@ -186,28 +188,36 @@ export default class ComicVineService extends Service {
} }
volumeIdString += `${volumeId}|`; volumeIdString += `${volumeId}|`;
}); });
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 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);
const foo = await axios({ const issueMatches = await axios({
url: `https://comicvine.gamespot.com/api/issues?api_key=${process.env.COMICVINE_API_KEY}`, url: `https://comicvine.gamespot.com/api/issues?api_key=${process.env.COMICVINE_API_KEY}`,
params: { params: {
resources: "issues", resources: "issues",
limit: "100", limit: "100",
format: "json", format: "json",
filter: filterString, filter: filterString,
query: ctx.params.scorerConfiguration.searchParams.searchTerms.name,
}, },
headers: {"User-Agent": "ThreeTwo"}, headers: {"User-Agent": "ThreeTwo"},
}); });
console.log(foo.data); console.log("YAHAHAHA", issueMatches.data.results.length);
return foo.data; // 3. get volume information for the issue matches
if(issueMatches.data.results.length === 1) {
const volumeInformation = await this.broker.call("comicvine.getVolumes", { volumeURI: issueMatches.data.results[0].volume.api_detail_url });
issueMatches.data.results[0].volumeInformation = volumeInformation;
return issueMatches.data;
}
const finalMatches = issueMatches.data.results.map(async (issue: any) => {
const volumeDetails = await this.broker.call("comicvine.getVolumes", { volumeURI: issue.volume.api_detail_url });
issue.volumeInformation = volumeDetails;
return issue;
});
return Promise.all(finalMatches);
}, },
@@ -229,10 +239,11 @@ export default class ComicVineService extends Service {
parseInt(data.number_of_total_results, 10) / parseInt(data.number_of_total_results, 10) /
parseInt(params.limit, 10) parseInt(params.limit, 10)
); );
console.log(totalPages);
if(parseInt(data.number_of_total_results, 10) <= 100 ) { if(parseInt(data.number_of_total_results, 10) <= 100 ) {
return [...data.results]; return [...data.results];
} }
if (currentPage < totalPages) { if (currentPage <= totalPages) {
output.push(...data.results); output.push(...data.results);
currentPage += 1; currentPage += 1;
params.page = currentPage; params.page = currentPage;

View File

@@ -116,7 +116,6 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
let subtitleMatchScore = 0; let subtitleMatchScore = 0;
if(!isNil(scorerConfiguration.searchParams.searchTerms.subtitle)) { if(!isNil(scorerConfiguration.searchParams.searchTerms.subtitle)) {
subtitleMatchScore = stringSimilarity.compareTwoStrings(scorerConfiguration.searchParams.searchTerms.subtitle, volume.name); subtitleMatchScore = stringSimilarity.compareTwoStrings(scorerConfiguration.searchParams.searchTerms.subtitle, volume.name);
console.log(scorerConfiguration.searchParams.searchTerms.subtitle, subtitleMatchScore);
if(subtitleMatchScore > 0.1) { if(subtitleMatchScore > 0.1) {
issueNameMatchScore += subtitleMatchScore; issueNameMatchScore += subtitleMatchScore;
} }
@@ -134,8 +133,8 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
volumeMatchScore += 3; volumeMatchScore += 3;
} }
} }
if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) { if(issueNameMatchScore > 0.2 && volumeMatchScore > 2) {
console.log("VOLUME SCORE: ", issueNameMatchScore); console.log(`Found a match for criteria, volume ID: ${volume.id}`);
return volume.id; return volume.id;
} }
}); });