fix(monitor): 策略3增加边界检查,防止误触发
问题:'? 插件下载见github'这种问句前无内容的情况也会触发剥离 修复: 1. 要求问句前至少有8个字符(避免单字符问句误触发) 2. 要求问句前至少有4个中文字符(确保是完整问句) 3. 要求问句后至少有4个中文字符(确保尾部有足够匹配内容) 测试覆盖: - ✓ 污染查询正确剥离 - ✓ 正常查询保持不变 - ✓ 边界情况不再误触发
This commit is contained in:
+6
-2
@@ -4770,10 +4770,14 @@ class MessageMonitor:
|
|||||||
# 使用纯中文相似度匹配,抵抗OCR噪声和英文/数字干扰
|
# 使用纯中文相似度匹配,抵抗OCR噪声和英文/数字干扰
|
||||||
if not stripped_bot:
|
if not stripped_bot:
|
||||||
q_mark_pos = max(ts.find('?'), ts.find('?'))
|
q_mark_pos = max(ts.find('?'), ts.find('?'))
|
||||||
if q_mark_pos >= 0 and q_mark_pos < len(ts) - 15:
|
# 确保问句前有足够内容(避免"? 插件下载..."这种误触发)
|
||||||
|
if q_mark_pos >= 0 and q_mark_pos >= 8 and q_mark_pos < len(ts) - 15:
|
||||||
|
before_q = ts[:q_mark_pos]
|
||||||
after_q = ts[q_mark_pos + 1:]
|
after_q = ts[q_mark_pos + 1:]
|
||||||
|
# 问句前必须有足够中文内容(至少4个汉字)
|
||||||
|
before_chinese = re.sub(r'[^\u4e00-\u9fff]', '', before_q)
|
||||||
after_chinese = re.sub(r'[^\u4e00-\u9fff]', '', after_q)
|
after_chinese = re.sub(r'[^\u4e00-\u9fff]', '', after_q)
|
||||||
if len(after_chinese) >= 4: # 尾部有足够中文内容
|
if len(before_chinese) >= 4 and len(after_chinese) >= 4:
|
||||||
for r in replied:
|
for r in replied:
|
||||||
if len(r) < 10:
|
if len(r) < 10:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user