/** * Checks if a manga's titles match the search title exactly or near-exactly. * Uses normalized comparison, similarity scoring, and word matching for validation. * @parammanga - The manga to validate * @paramsearchTitle - The search title to match against * @returns True if an exact or near-exact match is found * @source */ exportfunctionisExactMatch( manga: AniListManga, searchTitle: string, ): boolean { // Check all titles directly consttitlesToCheck = [ manga.title?.romaji, manga.title?.english, manga.title?.native, ...(manga.synonyms || []), ].filter(Boolean);
for (consttitleoftitlesToCheck) { if (!title) continue;
// Check different variations of the title against the search // This catches cases where normalization might miss things constnormalSearch = normalizeForMatching(searchTitle); constnormalTitle = normalizeForMatching(title);
// Check if titles are very similar after normalization // Increased threshold from 0.85 to 0.88 for stricter matching if ( normalTitle === normalSearch || calculateEnhancedSimilarity(normalTitle, normalSearch) > 88 ) { console.debug( `[MangaSearchService] ✅ Found good title match: "${title}" for "${searchTitle}"`, ); returntrue; }
// Check each word in the search query against the title constsearchWords = searchTitle .toLowerCase() .split(/\s+/) .filter((w) =>w.length > 1); consttitleLower = title.toLowerCase();
// If all important words from search are in the title, consider it a match constallWordsFound = searchWords.every((word) => titleLower.includes(word), ); // Require at least 2 words for this to be valid, otherwise matches might be too loose if (allWordsFound && searchWords.length >= 2) { console.debug( `[MangaSearchService] ✅ All search words found in title: "${title}"`, ); returntrue; } }
Exact match validation for manga filtering.
Source