def test_facets_filter_string_parsing_edge_cases(self):
        """Tests handling of filter strings with different parentheses placements in facet queries via API"""
        test_cases = [
            {
                "name": "Filter string with parentheses around the whole string",
                "filter": "(price:[49 TO 49.1] AND NOT color:red)",
                "exclude_terms": ["color:red"]
            },
            {
                "name": "Filter string with parentheses around term",
                "filter": "price:[49 TO 49.1] AND (NOT color:red)",
                "exclude_terms": ["color:red"]
            },
            {
                "name": "Filter string with parentheses around value",
                "filter": "price:[49 TO 49.1] AND NOT color:(red)",
                "exclude_terms": ["color:(red)"]
            }
        ]

        for test_case in test_cases:
            with self.subTest(test_case["name"]):
                res = self.client.index(self.unstructured_text_index_name).search(
                    "shirt",
                    search_method="HYBRID",
                    filter_string=test_case["filter"],
                    facets={
                        "fields": {
                            "color": {
                                "type": "string",
                                "excludeTerms": test_case["exclude_terms"]
                            }
                        }
                    }
                )
                self.assertIn("facets", res)
                self.assertIn("color", res["facets"])
Tests handling of filter strings with different parentheses placements in facet queries via API
tests/api_tests/v1/tests/api_tests/unstructured_index/test_facets.py