搜索字符串字段使用LIKE模糊匹配

This commit is contained in:
Hermes Agent 2026-06-22 13:40:02 +08:00
parent 7c64b70e74
commit 36267a18cc

View File

@ -171,6 +171,17 @@ ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
# 字符串字段使用LIKE模糊匹配
str_fields = {f['name'] for f in ori_fields if f.get('type') in ('str', 'text')}
if filterjson and str_fields:
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
filterjson = {'AND': [filterjson] if filterjson else []}
for fj in filterjson['AND']:
if fj.get('field') in str_fields and fj.get('op') == '=':
var = fj.get('var')
if var and var in ns and ns[var]:
ns[var] = f'%{ns[var]}%'
fj['op'] = 'LIKE'
{% if logined_userorgid or logined_userid %}
# 确保 logined 过滤条件始终生效
if filterjson: