fix(search): review ambiguous topic assignments

This commit is contained in:
2026-09-14 10:31:45 +03:00
parent a1b4787930
commit 5f44981bd3
4 changed files with 2749 additions and 2732 deletions

View File

@@ -57,7 +57,7 @@ def clean(value):
def group_for(label):
text = (label or "").casefold()
matches = [code for code, pattern in RULES if re.search(pattern, text)]
return matches[0] if matches else "review_required"
return matches[0] if len(matches) == 1 else "review_required"
def node_id(path):
@@ -121,8 +121,10 @@ def build(normalized_root):
path = source_root / code / "document.json"
try:
data = json.loads(path.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return code, []
except (OSError, json.JSONDecodeError) as error:
raise RuntimeError(f"cannot read normalized document {code}: {error}") from error
if not isinstance(data, dict):
raise RuntimeError(f"normalized document {code} must contain a JSON object")
return code, data.get("general_classifiers", [])
with ThreadPoolExecutor(max_workers=24) as pool: