SPB Git

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.8 KB · 42 lines python
Raw Blame History
1# Trouve-KA — tests du pipeline de requête et du ranking2# Author: Simon-Pierre Boucher3# Contact: contact@spboucher.ai45from trouveka.ranking import analyze_query, build_search_body678def test_language_detection_heuristics():9    assert analyze_query("meilleur programme de subvention pour thermopompe")["language"] == "fr"10    assert analyze_query("best heat pump rebate program")["language"] == "en"111213def test_location_extraction_with_accents():14    a = analyze_query("plombier gatineau")15    assert "gatineau" in a["locations"]16    b = analyze_query("subvention Trois-Rivières")17    assert any("trois-rivieres" in loc or "trois-rivières" in loc for loc in b["locations"])181920def test_body_structure_bm25_core():21    body, analysis = build_search_body("plombier Gatineau", page=2, limit=10)22    assert body["from"] == 10 and body["size"] == 1023    fs = body["query"]["function_score"]24    fields = fs["query"]["bool"]["must"][0]["multi_match"]["fields"]25    assert "title^4" in fields and "body" in fields and "body.en" in fields26    # Localité : fonction de boost présente quand un lieu est détecté27    locality = [f for f in fs["functions"] if "filter" in f]28    assert locality and locality[0]["filter"]["terms"]["locations"] == ["gatineau"]293031def test_filters():32    body, _ = build_search_body("test", language="fr", category="government", quebec_only=True)33    filters = body["query"]["function_score"]["query"]["bool"]["filter"]34    assert {"term": {"language": "fr"}} in filters35    assert {"term": {"categories": "government"}} in filters36    assert any("bool" in f for f in filters)  # quebec_only373839def test_no_locality_function_without_location():40    body, _ = build_search_body("recette de tourtière")41    assert not [f for f in body["query"]["function_score"]["functions"] if "filter" in f]42