• Process and rank search results, optionally caching them.

    Applies filtering, ranking, and custom matching rules.

    Parameters

    • results: AniListManga[]

      Raw search results from API

    • title: string

      Original search title

    • searchConfig: SearchServiceConfig

      Search configuration

    • OptionalkenmeiManga: KenmeiManga

      Optional Kenmei manga for custom rule evaluation

    Returns AniListManga[]

    Ranked manga results

    export function processSearchResults(
    results: AniListManga[],
    title: string,
    searchConfig: SearchServiceConfig,
    kenmeiManga?: KenmeiManga,
    ): AniListManga[] {
    console.debug(
    `[MangaSearchService] 🔍 Found ${results.length} raw results for "${title}" before filtering/ranking`,
    );

    let isExactMatchMode = searchConfig.exactMatchingOnly;

    if ((searchConfig.bypassCache && results.length > 0) || results.length <= 3) {
    isExactMatchMode = false;
    }

    const rankedResults = rankMangaResults(
    results,
    title,
    isExactMatchMode,
    searchConfig.bypassCache,
    kenmeiManga,
    );

    console.info(
    `[MangaSearchService] 🔍 Search complete for "${title}": Found ${results.length} results, ranked to ${rankedResults.length} relevant matches`,
    );

    // Cache results if not bypassing cache
    if (searchConfig.bypassCache) {
    console.debug(
    `[MangaSearchService] 🔍 MANUAL SEARCH: Skipping cache save for "${title}"`,
    );
    } else {
    const cacheKey = generateCacheKey(title);
    mangaCache[cacheKey] = {
    manga: rankedResults,
    timestamp: Date.now(),
    };
    saveCache();
    }

    return rankedResults;
    }