Kenmei manga entry to match.
Optionaltoken: stringOptional authentication token.
Optional search service configuration overrides.
Promise resolving to MangaMatchResult with best matches and status.
export async function matchSingleManga(
kenmeiManga: KenmeiManga,
token?: string,
config: Partial<SearchServiceConfig> = {},
): Promise<MangaMatchResult> {
const searchConfig = { ...DEFAULT_SEARCH_CONFIG, ...config };
// Search for potential matches
const searchResponse = await searchMangaByTitle(
kenmeiManga.title,
token,
searchConfig,
undefined,
undefined,
kenmeiManga,
);
const potentialMatches = searchResponse.matches;
// If using exact matching and we have matches, just use the top match
if (searchConfig.exactMatchingOnly && potentialMatches.length > 0) {
// Calculate a match score for the top result
const score = calculateMatchScore(
potentialMatches[0].manga,
kenmeiManga.title,
);
// If we have a good match, return it directly
if (score > 0.7) {
return {
kenmeiManga,
anilistMatches: [
{ manga: potentialMatches[0].manga, confidence: score * 100 },
],
selectedMatch: potentialMatches[0].manga,
status: "matched",
matchDate: new Date().toISOString(),
};
}
}
// Try using workers for parallel processing if enabled
const workerResult = await tryMatchWithWorkers(
kenmeiManga,
potentialMatches,
searchConfig,
searchConfig.shouldUseWorkers,
);
if (workerResult) {
return workerResult;
}
// Fallback: Use main thread
return findBestMatches(
kenmeiManga,
potentialMatches.map((match) => match.manga),
searchConfig.matchConfig,
);
}
Matches a single Kenmei manga with AniList entries using title similarity.
Searches for potential matches and applies the match engine to find the best candidate.