From 8b116ff824e9963dfdaedc690bd425b69a014a6b Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 16 Aug 2026 22:45:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=84=8F=E5=9B=BE=E5=8C=B9=E9=85=8D=E8=BF=87=E4=BA=8E=E5=AE=BD?= =?UTF-8?q?=E6=9D=BE=E5=AF=BC=E8=87=B4=E7=89=9B=E5=A4=B4=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E9=A9=AC=E5=98=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:用户问'登录插件下载地址'时,bot错误匹配到beibao.md(背包插件)而不是sdf1_login.md(登录插件) 根因:下载意图检查只要求标题包含'下载'就放行,没有验证其他核心关键词(如'登录'、'插件')是否匹配文档 修复: - 如果查询只有'下载'一个核心词 → 放宽检查(普通下载类查询) - 如果查询有多个核心词(如'登录插件下载地址')→ 要求至少一个其他核心词命中文档 - 未命中时记录debug日志便于排查 测试:预期'登录插件下载地址'现在应匹配sdf1_login.md而非beibao.md --- auto_reply.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/auto_reply.py b/auto_reply.py index 01c4ab7..487ea72 100644 --- a/auto_reply.py +++ b/auto_reply.py @@ -279,12 +279,36 @@ class AutoReply: _download_match = False if any(w in query for w in ('下载', '下到', '哪下', '在哪下', '怎么下')) and '下载' in heading_clean: if '
' not in heading and '- [' not in heading and '|-' not in heading: - _download_match = True + # ⭐ 修复:下载意图检查不能只靠"下载"放行,必须有其他核心词支撑 + # 否则"登录插件下载地址"会错误匹配到beibao.md的"下载地址" + # 规则: + # 1. 如果查询只有"下载"一个核心词 → 放宽检查(普通下载类查询) + # 2. 如果查询有多个核心词(如"登录插件下载地址")→ 要求至少一个其他核心词命中 + other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'} + if not other_core_kw: + # 只有"下载"一个核心词,直接放行 + _download_match = True + else: + # 有多个核心词,检查其他核心词是否命中文档 + other_hits = sum(1 for kw in other_core_kw if kw in doc_text) + if other_hits >= 1: + _download_match = True + else: + logger.debug( + f"下载意图拒绝(核心词未命中): query={query[:40]!r} " + f"doc_title={title!r} other_kw={other_core_kw!r} hits={other_hits}" + ) else: # 复合标题:检查标题主体部分(
或列表之前)是否含"下载" _title_part = re.split(r'
|- |\|-', heading_clean)[0] if '下载' in _title_part: - _download_match = True + other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'} + if not other_core_kw: + _download_match = True + else: + other_hits = sum(1 for kw in other_core_kw if kw in doc_text) + if other_hits >= 1: + _download_match = True if _download_match: logger.debug(f"下载意图放行: query={query[:30]!r} heading={heading[:30]!r}") return True