🔧 Fixed the issue when the page size was less than or equal to 100
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
import qs from "querystring";
|
||||
import https from "https";
|
||||
import { Service, ServiceBroker, Context } from "moleculer";
|
||||
import axios from "axios";
|
||||
import { cacheAdapterEnhancer, throttleAdapterEnhancer } from "axios-extensions";
|
||||
import {
|
||||
cacheAdapterEnhancer,
|
||||
throttleAdapterEnhancer,
|
||||
} from "axios-extensions";
|
||||
import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils";
|
||||
|
||||
const CV_BASE_URL = "https://comicvine.gamespot.com/api/";
|
||||
@@ -163,7 +167,10 @@ export default class ComicVineService extends Service {
|
||||
ctx.params,
|
||||
results,
|
||||
);
|
||||
return volumes;
|
||||
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);
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -171,14 +178,10 @@ export default class ComicVineService extends Service {
|
||||
fetchVolumesFromCV: async (params, output: any[] = []) => {
|
||||
let currentPage = parseInt(params.page, 10);
|
||||
const response = await axios.request({
|
||||
url:
|
||||
CV_BASE_URL +
|
||||
"search" +
|
||||
"?api_key=" +
|
||||
process.env.COMICVINE_API_KEY,
|
||||
url: `https://comicvine.gamespot.com/api/search?api_key=${process.env.COMICVINE_API_KEY}`,
|
||||
params,
|
||||
headers: { Accept: "application/json"},
|
||||
adapter: throttleAdapterEnhancer(cacheAdapterEnhancer(axios.defaults.adapter)),
|
||||
headers: {"User-Agent": "ThreeTwo"},
|
||||
|
||||
});
|
||||
|
||||
const { data } = response;
|
||||
@@ -187,21 +190,21 @@ export default class ComicVineService extends Service {
|
||||
parseInt(data.number_of_total_results, 10) /
|
||||
parseInt(params.limit, 10)
|
||||
);
|
||||
if(parseInt(data.number_of_total_results, 10) <= 100 ) {
|
||||
console.log("dari")
|
||||
return [...data.results];
|
||||
}
|
||||
if (currentPage < totalPages) {
|
||||
output.push(...data.results);
|
||||
|
||||
// 1a. Run the current batch of volumes through the matcher
|
||||
rankVolumes(output, params.scorerConfiguration);
|
||||
currentPage += 1;
|
||||
params.page = currentPage;
|
||||
console.log(`Fetching results for page ${currentPage}...`);
|
||||
return await this.fetchVolumesFromCV(params, output);
|
||||
} else {
|
||||
return { ...output };
|
||||
return [...output];
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
|
||||
// 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 )
|
||||
// 2. If there is a strong string comparison between the volume name and the issue name ??
|
||||
console.log(volumes.length);
|
||||
const issueNumber = parseInt(
|
||||
scorerConfiguration.searchParams.searchTerms.number,
|
||||
10
|
||||
@@ -96,7 +97,8 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
|
||||
const issueYear = parseISO(
|
||||
scorerConfiguration.searchParams.searchTerms.year
|
||||
);
|
||||
volumes.map(async (volume: any, idx: number) => {
|
||||
const foo = volumes.map((volume: any, idx: number) => {
|
||||
let volumeMatchScore = 0;
|
||||
const volumeStartYear = !isNil(volume.start_year)
|
||||
? parseISO(volume.start_year)
|
||||
: null;
|
||||
@@ -110,22 +112,23 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
|
||||
scorerConfiguration.searchParams.searchTerms.name,
|
||||
volume.name
|
||||
);
|
||||
if (
|
||||
!isNil(volumeStartYear) &&
|
||||
!isNil(firstIssueNumber) &&
|
||||
!isNil(lastIssueNumber) &&
|
||||
!isNil(issueNameMatchScore) &&
|
||||
(isSameYear(issueYear, volumeStartYear) ||
|
||||
isAfter(issueYear, volumeStartYear)) &&
|
||||
firstIssueNumber <= issueNumber &&
|
||||
issueNumber <= lastIssueNumber &&
|
||||
issueNameMatchScore > 0.5
|
||||
) {
|
||||
console.log("issue name match score", issueNameMatchScore);
|
||||
console.log(volume);
|
||||
if (!isNil(volumeStartYear)) {
|
||||
if (isSameYear(issueYear, volumeStartYear) ||
|
||||
isAfter(issueYear, volumeStartYear)) {
|
||||
volumeMatchScore += 2;
|
||||
}
|
||||
}
|
||||
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 volumes;
|
||||
return foo.filter((item: any) => !isNil(item));
|
||||
};
|
||||
|
||||
const calculateLevenshteinDistance = async (match: any, rawFileDetails: any) =>
|
||||
|
||||
Reference in New Issue
Block a user