fix: include matching body sections despite nonempty semantic recall

This commit is contained in:
2026-10-17 20:15:54 +08:00
parent eb8c545090
commit 93ff9c8c8d
3 changed files with 46 additions and 4 deletions
+7 -2
View File
@@ -391,11 +391,16 @@ def retrieve_targets(db, *, course_version_id: int, project_id: int, targets: li
substantive_only=target.get("use") != "structure",
semantic_pool=SEMANTIC_POOL, keyword_pool=KEYWORD_POOL)
hits = [normalize_hit(hit) for hit in (raw_hits or [])]
if target.get("use") == "content" and not hits and navigator is not None:
if target.get("use") == "content" and navigator is not None:
# The contents list may only be used to navigate: its headings are matched
# against headings that really occur in body text, and those sections and
# their neighbouring pages are searched. The quotation still lands on body.
hits = [dict(hit, via="toc_navigation") for hit in (navigator(target) or [])]
# Semantic recall always returns neighbours, even for a short vague
# query. Supplement it with matching body sections rather than waiting
# for zero hits, and keep those sections ahead of incidental matches.
navigated = [normalize_hit(hit) for hit in (navigator(target) or [])]
seen_ids = {hit["chunk_id"] for hit in navigated}
hits = navigated + [hit for hit in hits if hit["chunk_id"] not in seen_ids]
per_target[target["target_id"]] = hits
for hit in hits:
if hit["chunk_id"] not in seen:
+7 -1
View File
@@ -100,11 +100,17 @@ def _body_navigator(db, *, course_version_id, project_id, category):
label = normalize_heading(target.get("label") or "")
if not label:
return []
# A rubric often says simply "计划", while the actual section is future
# work. Expand only this concept; headings still have to exist in body text.
labels = [label]
plan_terms = ("计划", "后续改进", "后续工作", "未来工作", "下一阶段", "下一步")
if any(term in label for term in plan_terms):
labels.extend(plan_terms)
candidates = []
for heading, places in headings.items():
if not heading:
continue
if heading.startswith(label) or label.startswith(heading) or label in heading or heading in label:
if any(term in heading or heading in term for term in labels):
candidates.extend(places)
if not candidates:
return []