支持data_filter显式声明op(LIKE),不自动对所有字符串字段模糊匹配

This commit is contained in:
Hermes Agent 2026-06-22 13:53:30 +08:00
parent 36267a18cc
commit db5f579464

View File

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