mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-24 07:38:13 +02:00
fix: Clean domain URLs before SearXNG query (remove protocol, www, etc.)
This commit is contained in:
1 file changed
+27
-2
@@ -48,8 +48,12 @@ async def search(
|
|||||||
logger.warning("Aucun domaine spécifié pour la recherche")
|
logger.warning("Aucun domaine spécifié pour la recherche")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# Nettoyer les domaines (enlever protocole, www, etc.)
|
||||||
|
clean_domains = [_clean_domain(d) for d in domains]
|
||||||
|
clean_domains = [d for d in clean_domains if d] # Filtrer les vides
|
||||||
|
|
||||||
# Construire la requête avec site: pour chaque domaine
|
# Construire la requête avec site: pour chaque domaine
|
||||||
site_query = " OR ".join([f"site:{domain}" for domain in domains])
|
site_query = " OR ".join([f"site:{domain}" for domain in clean_domains])
|
||||||
full_query = f"{query} ({site_query})"
|
full_query = f"{query} ({site_query})"
|
||||||
|
|
||||||
logger.info(f"Recherche SearXNG: {full_query}")
|
logger.info(f"Recherche SearXNG: {full_query}")
|
||||||
@@ -87,7 +91,7 @@ async def search(
|
|||||||
|
|
||||||
# Vérifier que l'URL appartient à un des domaines ciblés
|
# Vérifier que l'URL appartient à un des domaines ciblés
|
||||||
url_domain = _extract_domain(url)
|
url_domain = _extract_domain(url)
|
||||||
if not any(domain in url_domain for domain in domains):
|
if not any(domain in url_domain for domain in clean_domains):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
@@ -131,6 +135,27 @@ def _extract_domain(url: str) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def _clean_domain(domain: str) -> str:
|
||||||
|
"""Nettoie un domaine (enlève protocole, www, slash final, etc.)"""
|
||||||
|
if not domain:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
domain = domain.strip()
|
||||||
|
|
||||||
|
# Si c'est une URL complète, extraire le domaine
|
||||||
|
if domain.startswith(("http://", "https://")):
|
||||||
|
domain = _extract_domain(domain)
|
||||||
|
else:
|
||||||
|
# Nettoyer le domaine directement
|
||||||
|
domain = domain.lower()
|
||||||
|
if domain.startswith("www."):
|
||||||
|
domain = domain[4:]
|
||||||
|
# Retirer le slash final
|
||||||
|
domain = domain.rstrip("/")
|
||||||
|
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
async def health_check() -> bool:
|
async def health_check() -> bool:
|
||||||
"""Vérifie que SearXNG est accessible"""
|
"""Vérifie que SearXNG est accessible"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user