davidtran999 commited on
Commit
f18b5ae
·
verified ·
1 Parent(s): f25c6dc

Upload backend/hue_portal/core/tests/test_hybrid_exact_boost.py with huggingface_hub

Browse files
backend/hue_portal/core/tests/test_hybrid_exact_boost.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from types import SimpleNamespace
3
+
4
+ from hue_portal.core.hybrid_search import calculate_exact_match_boost, _sort_by_exact_match
5
+
6
+
7
+ class HybridSearchExactMatchTests(unittest.TestCase):
8
+ def test_document_code_boost(self):
9
+ section = SimpleNamespace(
10
+ section_title="Điều 5",
11
+ section_code="Điều 5",
12
+ document=SimpleNamespace(code="QD-69-TW"),
13
+ )
14
+ boost = calculate_exact_match_boost(section, "theo quyết định 69", ["section_title"])
15
+ self.assertGreaterEqual(boost, 0.6)
16
+
17
+ def test_sort_promotes_exact_match(self):
18
+ obj_exact = object()
19
+ obj_regular = object()
20
+ filtered = [(obj_regular, 0.9), (obj_exact, 0.4)]
21
+ boosts = {obj_exact: 0.85, obj_regular: 0.0}
22
+
23
+ sorted_scores = _sort_by_exact_match(filtered, boosts)
24
+ self.assertIs(sorted_scores[0][0], obj_exact)
25
+
26
+
27
+ if __name__ == "__main__":
28
+ unittest.main()
29
+