mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
## Summary - normalize string items for list-valued metadata filters in `meta_filter` - fix `in` / `not in` case asymmetry when document metadata is lowercased but filter list values are not - add regression tests that cover the original issue scenario using uppercase list values ## Validation - `PYTHONPATH=external/ragflow pytest external/ragflow/test/unit_test/common/test_metadata_filter_operators.py -q` ## Notes - I commented on #14389 before opening this PR to claim the issue. - The new tests use `value=["F2", "F11"]` so they fail on the old implementation and pass with this fix. - This also benefits other non-comparison operators that flow through the same normalization path. Co-authored-by: copizza <copizza@users.noreply.github.com> Co-authored-by: Wang Qi <wangq8@outlook.com>
This commit is contained in:
@@ -42,6 +42,13 @@ def convert_conditions(metadata_condition):
|
||||
def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
|
||||
doc_ids = set([])
|
||||
|
||||
def normalize_string_values(value):
|
||||
if isinstance(value, str):
|
||||
return value.lower()
|
||||
if isinstance(value, list):
|
||||
return [item.lower() if isinstance(item, str) else item for item in value]
|
||||
return value
|
||||
|
||||
def filter_out(v2docs, operator, value):
|
||||
ids = []
|
||||
for input, docids in v2docs.items():
|
||||
@@ -96,14 +103,8 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
|
||||
value = value.lower()
|
||||
else:
|
||||
# Non-comparison operators: maintain original logic
|
||||
if isinstance(input, str):
|
||||
input = input.lower()
|
||||
elif operator in ("in", "not in") and isinstance(input, list):
|
||||
input = [x.lower() if isinstance(x, str) else x for x in input]
|
||||
if isinstance(value, str):
|
||||
value = value.lower()
|
||||
elif operator in ("in", "not in") and isinstance(value, list):
|
||||
value = [x.lower() if isinstance(x, str) else x for x in value]
|
||||
input = normalize_string_values(input)
|
||||
value = normalize_string_values(value)
|
||||
|
||||
matched = False
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user