修复三个OCR过滤问题:

1. Task #1440: 时间戳过滤器加强到5分钟窗口
   - 继承时间戳超过5分钟(300s)的消息直接丢弃
   - 修复:12:09的消息能通过13:49的过滤器(差100分钟)

2. Task #1441: bot自身消息查库过滤
   - 新增get_recent_bot_replies方法查询数据库
   - 检查OCR读到的内容与数据库中bot回复重合率≥90%则丢弃
   - 修复:bot回复的消息被OCR读到后直接回复用户的问题

3. Task #1442: 数据库时间戳混乱修复
   - 修改record_bot_reply和record_user_message使用本地时间
   - SQLite的CURRENT_TIMESTAMP返回UTC时间导致时间戳混乱
   - 修复:部分消息created_at在凌晨但实际测试不在凌晨

同时包含Task #1436的链接文本清理修复
This commit is contained in:
youpaishidifu
2026-08-07 14:09:29 +08:00
parent ad091561fe
commit 5627a2b88a
3 changed files with 77 additions and 15 deletions
+17 -6
View File
@@ -73,7 +73,7 @@ class AutoReply:
else:
sender = None
return {"platform": platform, "answer": answer, "sender": sender}
return {"platform": platform, "answer": answer, "sender": sender, "msg": msg}
@staticmethod
def _has_content_relevance(query: str, doc: dict, score: float = 0.0) -> bool:
@@ -88,18 +88,28 @@ class AutoReply:
if len(q_tokens) <= 2:
return True # 短查询不拦截
# 1. 检查 heading + title
doc_text = doc.get("heading", "") + " " + doc.get("title", "")
# 1. 检查 heading + title(排除链接文本)
heading = doc.get("heading", "")
title = doc.get("title", "")
# 清理 heading 中的 Markdown 链接:[text](url) → text
_link_pattern = re.compile(r'\[([^\]]*)\]\([^\)]+\)')
heading_clean = _link_pattern.sub(r'\1', heading)
# 进一步清理:去掉链接文本本身
heading_no_link = _link_pattern.sub('', heading)
doc_text = heading_clean + " " + title
d_tokens = set(t for t in jieba.cut(doc_text) if len(t) >= 2)
has_heading_hit = bool(q_tokens & d_tokens)
# 2. 检查 content/body(TF-IDF匹配的段落正文)
# 2. 检查 content/body(排除链接文本)
body = doc.get("content", "") or doc.get("body", "")
b_tokens = set()
has_body_hit = False
if body:
# 清理 body 中的链接文本,防止 "[sdf1_login登录插件](sdf1_login.md)" 误匹配
body_clean = _link_pattern.sub(r'\1', body)
body_no_link = _link_pattern.sub('', body)
# 截断前500字防超长文档
b_tokens = set(t for t in jieba.cut(body[:500]) if len(t) >= 2)
b_tokens = set(t for t in jieba.cut(body_no_link[:500]) if len(t) >= 2)
has_body_hit = bool(q_tokens & b_tokens)
# 动作/配置类查询:不能只命中标题,正文必须也含核心词
@@ -120,7 +130,8 @@ class AutoReply:
# 3. 子串回退:jieba分词可能产生"包是""还是"等碎片token,
# 导致token交集为空但文档确实包含查询核心词(如"资源包")。
# 检查查询中任意2~6字子串是否出现在文档文本中。
full_text = doc_text + " " + body[:500]
# ⭐ 使用清理后的文本(排除链接文本)
full_text = doc_text + " " + body_no_link[:500] if body else doc_text
stripped_query = re.sub(r'[??!!。,,\s]', '', query)
if len(stripped_query) >= 4:
for qlen in range(min(len(stripped_query), 6), 1, -1):