• Convert match score to confidence percentage using conservative adaptive scaling. Applies different thresholds based on match score ranges to avoid overconfidence.

    Parameters

    • searchTitle: string

      The search title used for matching

    • manga: AniListManga

      The manga to calculate confidence for

    Returns number

    Confidence percentage between 0-100 (capped at 99% for near-perfect matches)

    export function calculateConfidence(
    searchTitle: string,
    manga: AniListManga,
    ): number {
    const matchDetails = calculateMatchScoreDetails(manga, searchTitle);
    const { score, matchType } = matchDetails;

    console.debug(
    `[MangaSearchService] Calculating confidence for match score: ${score.toFixed(3)} (${matchType}) between "${searchTitle}" and "${manga.title.english || manga.title.romaji}"`,
    );

    if (score <= 0) {
    return 0;
    }

    const logisticValue =
    1 / (1 + Math.exp(-LOGISTIC_STEEPNESS * (score - LOGISTIC_MIDPOINT)));
    const baseConfidence = CONFIDENCE_FLOOR + logisticValue * CONFIDENCE_RANGE;
    const adjustment = MATCH_TYPE_BIAS[matchType] ?? 0;
    const adjustedConfidence = Math.min(
    MAX_CONFIDENCE,
    Math.max(CONFIDENCE_FLOOR, baseConfidence + adjustment),
    );
    return Math.round(adjustedConfidence);
    }