# Trouve-KA — tests du pipeline de requête et du ranking # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai from trouveka.ranking import analyze_query, build_search_body def test_language_detection_heuristics(): assert analyze_query("meilleur programme de subvention pour thermopompe")["language"] == "fr" assert analyze_query("best heat pump rebate program")["language"] == "en" def test_location_extraction_with_accents(): a = analyze_query("plombier gatineau") assert "gatineau" in a["locations"] b = analyze_query("subvention Trois-Rivières") assert any("trois-rivieres" in loc or "trois-rivières" in loc for loc in b["locations"]) def test_body_structure_bm25_core(): body, analysis = build_search_body("plombier Gatineau", page=2, limit=10) assert body["from"] == 10 and body["size"] == 10 fs = body["query"]["function_score"] fields = fs["query"]["bool"]["must"][0]["multi_match"]["fields"] assert "title^4" in fields and "body" in fields and "body.en" in fields # Localité : fonction de boost présente quand un lieu est détecté locality = [f for f in fs["functions"] if "filter" in f] assert locality and locality[0]["filter"]["terms"]["locations"] == ["gatineau"] def test_filters(): body, _ = build_search_body("test", language="fr", category="government", quebec_only=True) filters = body["query"]["function_score"]["query"]["bool"]["filter"] assert {"term": {"language": "fr"}} in filters assert {"term": {"categories": "government"}} in filters assert any("bool" in f for f in filters) # quebec_only def test_no_locality_function_without_location(): body, _ = build_search_body("recette de tourtière") assert not [f for f in body["query"]["function_score"]["functions"] if "filter" in f]