From 53cf1d6b70073ba098f14ed95a93bf18c1882435 Mon Sep 17 00:00:00 2001 From: "34047007@qq.com" <34047007@qq.com> Date: Tue, 28 Jul 2026 16:33:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20test=5Flowercase=5F?= =?UTF-8?q?boolean=5Fdetected=20=E6=96=AD=E8=A8=80=E5=8C=B9=E9=85=8D=20R20?= =?UTF-8?q?=20re.IGNORECASE=20=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P20 R20-3 为 is_pubmed_syntax() 布尔正则添加了 re.IGNORECASE, 小写 and/or/not 现在正确触发 PubMed 语法检测。更新测试断言以匹配新行为, 并在 P1-2 文档中注明 P20 修订。 --- backend/tests/test_pubmed_query_parser.py | 4 ++-- docs/13-搜索修复全记录.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/tests/test_pubmed_query_parser.py b/backend/tests/test_pubmed_query_parser.py index 0678e9d..b0c87ab 100644 --- a/backend/tests/test_pubmed_query_parser.py +++ b/backend/tests/test_pubmed_query_parser.py @@ -32,8 +32,8 @@ class TestIsPubmedSyntax: assert not is_pubmed_syntax(None) def test_lowercase_boolean_detected(self): - """小写的 and/or/not 不识别为 PubMed 语法(P11: 仅大写 AND/OR/NOT 才是 PubMed 布尔符)""" - assert not is_pubmed_syntax("cancer and therapy") + """小写的 and/or/not 识别为 PubMed 语法(P20: 添加 re.IGNORECASE,统一处理大小写)""" + assert is_pubmed_syntax("cancer and therapy") class TestTokenise: diff --git a/docs/13-搜索修复全记录.md b/docs/13-搜索修复全记录.md index da6bb8b..86bb73f 100644 --- a/docs/13-搜索修复全记录.md +++ b/docs/13-搜索修复全记录.md @@ -860,6 +860,7 @@ - **根因**:`re.search` 使用 `re.IGNORECASE` 标志。`"diet and exercise in cancer"` 中的 `and` 被识别为 PubMed 布尔符 → 触发 PubMed 路径 → 删除 "and"、"in" 等 stop words → 搜索结果恶化 - **修复**:移除 `re.IGNORECASE`。PubMed 官方仅识别**大写** `AND/OR/NOT` 为布尔符 - **验证**:`test_lowercase_boolean_detected` 断言从 `assert is_pubmed_syntax` 改为 `assert not is_pubmed_syntax` +- **P20 修订**:`is_pubmed_syntax()` 重新添加 `re.IGNORECASE`(R20 Bug-R20-3)。停用词过滤早已移除,不再有退化风险;统一处理大小写可捕获 `cancer and therapy` 等小写 PubMed 查询 ### P1-3: `_relevance_query` 对 MeSH-only 查询为空(HIGH)