fix: 混合布尔丢失 OR — boolean_operator="mixed" 引擎分支修复
CI / backend (push) Canceled after 0s
CI / frontend (push) Canceled after 0s

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 合并所有正条件
This commit is contained in:
34047007@qq.com
2026-07-27 15:15:15 +08:00
parent 5b9fcff82e
commit 2169308e67
+3 -3
View File
@@ -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 项应独立 ANDPubMed: A OR B NOT C = (A OR B) AND NOT C
# OR/mixed 模式下 NOT 项应独立 ANDPubMed: 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