diff --git a/integrations/astra/src/haystack_integrations/document_stores/astra/filters.py b/integrations/astra/src/haystack_integrations/document_stores/astra/filters.py index e313ae13a..61f3e5402 100644 --- a/integrations/astra/src/haystack_integrations/document_stores/astra/filters.py +++ b/integrations/astra/src/haystack_integrations/document_stores/astra/filters.py @@ -73,7 +73,7 @@ def _parse_logical_condition(condition: Dict[str, Any]) -> Dict[str, Any]: raise FilterError(msg) operator = condition["operator"] - conditions = [_parse_comparison_condition(c) for c in condition["conditions"]] + conditions = [_normalize_filters(c) for c in condition["conditions"]] if len(conditions) > 1: conditions = _normalize_ranges(conditions) if operator not in OPERATORS: diff --git a/integrations/astra/tests/test_document_store.py b/integrations/astra/tests/test_document_store.py index a9f1542e9..df181ad8c 100644 --- a/integrations/astra/tests/test_document_store.py +++ b/integrations/astra/tests/test_document_store.py @@ -172,6 +172,34 @@ def test_delete_documents_more_than_twenty_delete_ids(self, document_store: Astr # No Document has been deleted assert document_store.count_documents() == 0 + def test_filter_documents_nested_filters(self, document_store, filterable_docs): + filter_criteria = { + "operator": "AND", + "conditions": [ + {"field": "meta.page", "operator": "==", "value": "100"}, + { + "operator": "OR", + "conditions": [ + {"field": "meta.chapter", "operator": "==", "value": "abstract"}, + {"field": "meta.chapter", "operator": "==", "value": "intro"}, + ], + }, + ], + } + + document_store.write_documents(filterable_docs) + result = document_store.filter_documents(filters=filter_criteria) + + self.assert_documents_are_equal( + result, + [ + d + for d in filterable_docs + if d.meta.get("page") == "100" + and (d.meta.get("chapter") == "abstract" or d.meta.get("chapter") == "intro") + ], + ) + @pytest.mark.skip(reason="Unsupported filter operator not.") def test_not_operator(self, document_store, filterable_docs): pass