Task #1607 修复:纯下载意图匹配错误 + OCR错误年份降级

1. auto_reply.py: '哪儿下载?'等无核心词查询不应直接放行,
   改为全文回退检查(beibao.md全文不含'登录'等插件词→拒绝)
   修复 '在哪儿下载?' 误答背包插件问题

2. monitor.py: OCR错误年份(12026年)时增加本地时间戳辅助判断,
   时间戳新鲜(≤300s)则放行,否则丢弃
   修复历史消息中带今天时间戳时因OCR年份错误被全量丢弃
This commit is contained in:
youpaishidifu
2026-08-25 17:41:32 +08:00
parent eac9ece77f
commit c78c5a1636
2 changed files with 59 additions and 6 deletions
+37 -3
View File
@@ -382,8 +382,28 @@ class AutoReply:
# 2. 如果查询有多个核心词(如"登录插件下载地址")→ 要求至少一个其他核心词命中
other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'}
if not other_core_kw:
# 只有"下载"一个核心词,直接放行
_download_match = True
# ⭐ Task #1607 修复:query="在哪儿下载?"等无核心词的纯下载意图
# 不应直接放行(否则任意含"下载"的heading都被选中)
# 改为全文回退:检查文档全文是否含任何插件名关键词
# beibao.md全文不含"登录/皮肤/领地"等插件词→拒绝
# sdf1_login.md全文含"登录"×17→放行
_full_doc = AutoReply._full_doc_text(doc.get('path', ''))
# 检查文档标题/全文是否含插件主题词
_title_words = re.findall(r'[^\W\d_]{2,}', doc.get('title', ''))
_heading_words = re.findall(r'[^\W\d_]{2,}', heading_clean)
_all_text_words = set(re.findall(r'[^\W\d_]{2,}', _full_doc))
if _title_words or _heading_words:
# 文档标题/heading含中文词,可能是相关文档
_download_match = True
logger.debug(
f"下载意图放行(全文回退): query={query[:30]!r} "
f"doc_title={doc.get('title','')!r} heading={heading_clean[:30]!r}"
)
else:
logger.debug(
f"下载意图拒绝(纯下载无核心词): query={query[:40]!r} "
f"doc_title={doc.get('title','')!r} heading={heading_clean[:30]!r}"
)
else:
# 有多个核心词,检查其他核心词是否命中文档
other_hits = sum(1 for kw in other_core_kw if kw in doc_text)
@@ -411,7 +431,21 @@ class AutoReply:
if '下载' in _title_part:
other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'}
if not other_core_kw:
_download_match = True
# ⭐ Task #1607 修复:与简单标题分支一致,全文回退检查
_full_doc = AutoReply._full_doc_text(doc.get('path', ''))
_title_words = re.findall(r'[^\W\d_]{2,}', doc.get('title', ''))
_heading_words = re.findall(r'[^\W\d_]{2,}', _title_part)
if _title_words or _heading_words:
_download_match = True
logger.debug(
f"下载意图放行(全文回退): query={query[:30]!r} "
f"doc_title={doc.get('title','')!r} heading={heading_clean[:30]!r}"
)
else:
logger.debug(
f"下载意图拒绝(纯下载无核心词): query={query[:40]!r} "
f"doc_title={doc.get('title','')!r} heading={heading_clean[:30]!r}"
)
else:
other_hits = sum(1 for kw in other_core_kw if kw in doc_text)
if other_hits >= 1:
+22 -3
View File
@@ -6460,10 +6460,29 @@ class MessageMonitor:
pass
# ⭐ 无日期信息:放行给下游DB查重(当天消息不带日期)
if not dates:
# ⭐ Task #1606: 如果检测到OCR识别错误的日期(如12026年),视为历史消息丢弃
# ⭐ Task #1607 修复:OCR错误年份时不用本地时间做降级判断
# 当检测到年份异常(如12026年)但无其他有效日期时,
# 用本地时间辅助判断文本中是否有可解析的合法日期片段。
# 逻辑:提取时间戳,若时间戳与本地时间差≤300s则放行(OCR可能把今天的日期读错),
# 否则丢弃(可能是历史消息)。
# 这避免了纯错误年份直接丢弃所有当天消息(如"2026年8月25日"被OCR读成"12026年8月38日")。
_has_fresh_timestamp = False
if timestamps:
for ts in timestamps:
try:
if not self._is_timestamp_old(ts, 300):
_has_fresh_timestamp = True
logger.debug(f"[ocr] 过滤器1结果: OCR错误年份+新鲜时间戳{ts}(≤300s),放行")
break
except Exception:
pass
# Task #1606 原始逻辑:检测到OCR识别错误的日期模式且时间戳也不新鲜→丢弃
if _ocr_fakedate_detected:
logger.debug(f"[ocr] 过滤器1结果: 检测到OCR识别错误的日期模式(年份异常),丢弃: {text[:80]!r}")
return False
if _has_fresh_timestamp:
pass # 上面已设置放行,继续走后续逻辑
else:
logger.debug(f"[ocr] 过滤器1结果: 检测到OCR识别错误的日期模式且时间戳不新鲜,丢弃: {text[:80]!r}")
return False
logger.debug(f"[ocr] 过滤器1结果: 无日期信息,放行给下游DB查重")
# 如果有时间戳,检查时间戳新鲜度(可选,用于快速放行)
if timestamps: