From 2169308e67646e04eae377a3f6fef85300db09ee Mon Sep 17 00:00:00 2001 From: "34047007@qq.com" <34047007@qq.com> Date: Mon, 27 Jul 2026 15:15:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=B7=E5=90=88=E5=B8=83=E5=B0=94?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=20OR=20=E2=80=94=20boolean=5Foperator=3D"mix?= =?UTF-8?q?ed"=20=E5=BC=95=E6=93=8E=E5=88=86=E6=94=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit boolean_operator 有三种值:and/or/mixed。引擎只处理了 "or", "mixed" 落到了 else(AND),导致 A OR B AND C 中 OR 完全丢失。 修复两处: - field_combine: 用 or_ 当 string(mixed) 场景,因为各组内是 OR 关系 - term_conditions 合并: mixed 与 or 同逻辑,OR 合并所有正条件 --- backend/app/services/search_engine.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/app/services/search_engine.py b/backend/app/services/search_engine.py index d36151a..f9d9661 100644 --- a/backend/app/services/search_engine.py +++ b/backend/app/services/search_engine.py @@ -613,7 +613,7 @@ class AdvancedSearchEngine: term_conditions: list = [] # 1. 字段级搜索 [TI] [AB] [TIAB] [AU] [TA] [LA] [VI] [IP] [PG] [LID] - field_combine = or_ if pp.boolean_operator == "or" else and_ + field_combine = or_ if pp.boolean_operator in ("or", "mixed") else and_ field_map = { "title": pp.title_terms, "abstract": pp.abstract_terms, @@ -949,10 +949,10 @@ class AdvancedSearchEngine: # 将 term_conditions 加入 conditions if term_conditions: - if pp.boolean_operator == "or": + if pp.boolean_operator in ("or", "mixed"): from sqlalchemy.sql.elements import UnaryExpression from sqlalchemy.sql import operators as _sa_ops - # OR 模式下 NOT 项应独立 AND(PubMed: A OR B NOT C = (A OR B) AND NOT C) + # OR/mixed 模式下 NOT 项应独立 AND(PubMed: A OR B NOT C = (A OR B) AND NOT C) pos_conds = [c for c in term_conditions if not (isinstance(c, UnaryExpression) and c.modifier == _sa_ops.inv)] neg_conds = [c for c in term_conditions