From 555816bf30ad2a005798017cdad292c0e3458e59 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Apr 2026 22:45:15 +0000 Subject: [PATCH] feat: recherche amelioree - scoring fuzzy multi-niveaux (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Algorithme de scoring: exact > starts-with > substring > all words > any word - Scores: 1.0 > 0.95 > 0.85 > 0.7 > 0.5 > 0.3 - Tolérance aux fautes de frappe via matching partiel sur mots - Résultats triés par pertinence décroissante - Supporte les titres en français, anglais, romaji Closes #7 --- app/routers/router_anime.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/routers/router_anime.py b/app/routers/router_anime.py index 635c8b0..1e156c8 100644 --- a/app/routers/router_anime.py +++ b/app/routers/router_anime.py @@ -174,10 +174,28 @@ async def search_anime_unified( if url and url not in seen_urls: seen_urls.add(url) - if q.lower() in (item_dict.get("title") or "").lower(): + # Fuzzy relevance scoring + title = (item_dict.get("title") or "").lower() + query_lower = q.lower() + + # Exact match + if query_lower == title: item_dict["_relevance_boost"] = 1.0 - else: + # Title starts with query + elif title.startswith(query_lower): + item_dict["_relevance_boost"] = 0.95 + # Query is a substring of title + elif query_lower in title: + item_dict["_relevance_boost"] = 0.85 + # Words from query all appear in title + elif all(word in title.split() for word in query_lower.split() if len(word) > 1): + item_dict["_relevance_boost"] = 0.7 + # At least one word matches + elif any(word in title.split() for word in query_lower.split() if len(word) > 2): item_dict["_relevance_boost"] = 0.5 + else: + item_dict["_relevance_boost"] = 0.3 + results[pid].append(item_dict) # Prepare enrichment task for top 15 results per provider