Kenmei manga to match.
AniList manga candidate.
Partial config to override defaults.
Match result with confidence (0-100), exact match flag, and matched field.
export function scoreMatch(
kenmeiManga: KenmeiManga,
anilistManga: AniListManga,
config: Partial<MatchEngineConfig> = {},
): { confidence: number; isExactMatch: boolean; matchedField: string } {
const matchConfig = { ...DEFAULT_MATCH_CONFIG, ...config };
const {
isCaseSensitive,
shouldPreferEnglishTitles,
shouldPreferRomajiTitles,
shouldUseAlternativeTitles,
} = matchConfig;
// Normalize the Kenmei title
const kenmeiTitle = normalizeString(kenmeiManga.title, isCaseSensitive);
// Skip extremely short titles (likely errors)
if (kenmeiTitle.length < matchConfig.minTitleLength) {
return { confidence: 0, isExactMatch: false, matchedField: "none" };
}
// Array to store all similarity scores with their sources
const scores: Array<{ field: string; score: number }> = [];
// Check primary titles - early return if exact match found
const primaryMatch = scorePrimaryTitles(kenmeiTitle, anilistManga, scores);
if (primaryMatch) return primaryMatch;
// Check alternative titles if enabled - early return if exact match found
if (shouldUseAlternativeTitles) {
const synonymMatch = scoreSynonyms(kenmeiTitle, anilistManga, scores);
if (synonymMatch) return synonymMatch;
const altTitleMatch = scoreAlternativeTitles(
kenmeiManga,
anilistManga,
isCaseSensitive,
matchConfig.minTitleLength,
scores,
);
if (altTitleMatch) return altTitleMatch;
}
// Calculate final score with preferences
return calculateFinalScore(
scores,
shouldPreferEnglishTitles,
shouldPreferRomajiTitles,
);
}
Scores a Kenmei manga against an AniList entry using comprehensive title comparison.
Checks primary titles, synonyms, and alternative titles in sequence, returning early on exact match (100%). Final score determined by highest similarity.