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