diff --git a/services/comicvine.service.ts b/services/comicvine.service.ts index d1e25ca..1be2f73 100644 --- a/services/comicvine.service.ts +++ b/services/comicvine.service.ts @@ -154,12 +154,15 @@ export default class ComicVineService extends Service { offset: number; resources: string; scorerConfiguration?: { - searchQuery: { - issue: object; - series: object; + searchParams: { + searchTerms: { + name: string; + number: string; + year: string; + }; }; - rawFileDetails: object; }; + rawFileDetails: object; }> ) => { const results: any = []; @@ -167,10 +170,39 @@ export default class ComicVineService extends Service { ctx.params, results, ); - console.log("total volumes", volumes.length); - // 1a. Run the current batch of volumes through the matcher - // Check for: issue year falling in the range of the volume run - return rankVolumes(volumes, ctx.params.scorerConfiguration); + // 1. Run the current batch of volumes through the matcher + const potentialVolumeMatches = rankVolumes(volumes, ctx.params.scorerConfiguration); + // 2. Construct the filter string + // 2a. volume: 1111|2222|3333 + let volumeIdString = "volume:"; + potentialVolumeMatches.map((volumeId: string, idx: number) => { + if(idx >= potentialVolumeMatches.length - 1) { + volumeIdString += `${volumeId}`; + return volumeIdString; + } + volumeIdString += `${volumeId}|`; + }); + const issueYear = parseInt(ctx.params.scorerConfiguration.searchParams.searchTerms.year, 10); + // 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015 + const coverDateFilter = `cover_date:${issueYear - 1}-01-01|${issueYear + 1}-12-31`; + const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.searchTerms.number},${volumeIdString},${coverDateFilter}`; + console.log(filterString); + + const foo = await axios({ + url: `https://comicvine.gamespot.com/api/issues?api_key=${process.env.COMICVINE_API_KEY}`, + params: { + resources: "issues", + limit: "100", + format: "json", + filter: filterString, + query: ctx.params.scorerConfiguration.searchParams.searchTerms.name, + }, + headers: {"User-Agent": "ThreeTwo"}, + }); + console.log(foo.data); + return foo.data; + + }, }, }, @@ -191,7 +223,6 @@ export default class ComicVineService extends Service { parseInt(params.limit, 10) ); if(parseInt(data.number_of_total_results, 10) <= 100 ) { - console.log("dari") return [...data.results]; } if (currentPage < totalPages) { diff --git a/utils/searchmatchscorer.utils.ts b/utils/searchmatchscorer.utils.ts index 8319212..bc05a78 100644 --- a/utils/searchmatchscorer.utils.ts +++ b/utils/searchmatchscorer.utils.ts @@ -112,20 +112,22 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => { scorerConfiguration.searchParams.searchTerms.name, volume.name ); + // 1. If issue year starts after the candidate volume's start year or is the same year, +2 to volumeMatchScore if (!isNil(volumeStartYear)) { if (isSameYear(issueYear, volumeStartYear) || isAfter(issueYear, volumeStartYear)) { volumeMatchScore += 2; } } + // 2. 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(firstIssueNumber <= issueNumber || issueNumber <= lastIssueNumber) { volumeMatchScore += 3; - } + } } if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) { console.log("VOLUME SCORE: ", volumeMatchScore); - return volume; + return volume.id; } }); return foo.filter((item: any) => !isNil(item));