From cddb3e82ff85937752d79104f3cba781112c589e Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 11 Dec 2025 16:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=9B=B4=E4=B8=B0=E5=AF=8C?= =?UTF-8?q?=E7=9A=84=E7=95=AA=E5=8F=B7=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/fanhao_search/main.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/fanhao_search/main.py b/plugins/fanhao_search/main.py index eb6c85b..bfde55b 100644 --- a/plugins/fanhao_search/main.py +++ b/plugins/fanhao_search/main.py @@ -147,7 +147,20 @@ class FanhaoSearchPlugin(MessagePluginInterface): raise def _normalize_code(self, text: str) -> str: - return (text or "").strip().upper() + # 1. 基础清理:判空、去首尾空格、转大写 + text = (text or "").strip().upper() + # 用户输入 处理后 说明 + # IPzz108 IPZZ-108 目标场景:自动补全了横杠 + # ipzz108 IPZZ-108 全小写自动转大写并补全 + # IPZZ-108 IPZZ-108 已经有横杠,正则不匹配(字母后是横杠不是数字),保持原样 + # ipzz-108 IPZZ-108 小写带横杠,仅转大写,保持原样 + # ipzz108 IPZZ-108 去除前后空格 + # A1 A-1 极短代码也能兼容 + + # 2. 核心逻辑:使用正则查找“字母后面紧跟数字”的情况,并在中间插入横杠 + # r'([A-Z])(\d)' 含义:捕获组1是任意大写字母,捕获组2是任意数字 + # r'\1-\2' 含义:将匹配到的内容替换为“组1 + 横杠 + 组2” + return re.sub(r'([A-Z])(\d)', r'\1-\2', text) def _build_queries(self, code_upper: str) -> List[Dict[str, Any]]: # 精确匹配查询