spb/trouve-ka Public
Trouve-KA — moteur de recherche web indépendant, Québec-first. Crawler distribué, index OpenSearch, ranking bilingue, galerie d'images. En prod : www.trouve-ka.com
Python 76.8%
TypeScript 15.7%
SQL 3.9%
Shell 1.4%
CSS 1.3%
Dockerfile 0.7%
1# Trouve-KA — priorités et recrawl adaptatif2# Author: Simon-Pierre Boucher3# Contact: contact@spboucher.ai45"""Fonction de priorité du frontier et scheduling de recrawl.67P = w_q·Q + w_a·A + w_f·F + w_l·L + w_n·N − w_d·D − w_s·S (CLAUDE.md §5.3)8Les poids sont des constantes nommées, destinées à être calibrées par mesures.9"""1011from datetime import timedelta1213# Poids de la fonction de priorité — à calibrer empiriquement, jamais figés14W_QUEBEC = 0.4015W_AUTHORITY = 0.1516W_FRESHNESS = 0.1017W_LINKS = 0.1018W_NOVELTY = 0.1519W_DEPTH = 0.0520W_SPAM = 0.30212223def compute_priority(24 *,25 domain_quebec_score: float,26 authority_score: float = 0.0,27 freshness_hint: float = 0.0,28 link_signal: float = 0.0,29 is_new_domain: bool = False,30 depth: int = 0,31 spam_signal: float = 0.0,32 is_seed: bool = False,33) -> float:34 """Priorité ∈ [0, 1]. Les seeds démarrent au maximum."""35 if is_seed:36 return 1.037 p = (38 W_QUEBEC * domain_quebec_score39 + W_AUTHORITY * min(authority_score, 1.0)40 + W_FRESHNESS * min(freshness_hint, 1.0)41 + W_LINKS * min(link_signal, 1.0)42 + W_NOVELTY * (1.0 if is_new_domain else 0.3)43 - W_DEPTH * min(depth, 10) / 10.044 - W_SPAM * min(spam_signal, 1.0)45 )46 return max(0.0, min(1.0, round(p, 4)))474849def next_recrawl_delay(50 *,51 changed: bool,52 previous_delay_hours: float | None,53 min_hours: float = 1.0,54 max_hours: float = 24 * 30.0,55 default_hours: float = 24.0,56) -> timedelta:57 """Recrawl adaptatif (§5.5) : page inchangée → intervalle ×2; page volatile → intervalle ÷2."""58 prev = previous_delay_hours or default_hours59 hours = max(min_hours, prev / 2.0) if changed else min(max_hours, prev * 2.0)60 return timedelta(hours=hours)616263def retry_delay(retries: int) -> timedelta:64 """Backoff exponentiel plafonné pour les erreurs transitoires."""65 return timedelta(minutes=min(15 * (2**retries), 60 * 24))66