diff --git a/rest_api/rest_api/controller/search.py b/rest_api/rest_api/controller/search.py index 038d71347..e5747f206 100644 --- a/rest_api/rest_api/controller/search.py +++ b/rest_api/rest_api/controller/search.py @@ -1,6 +1,5 @@ from typing import Dict, Any -from collections.abc import Mapping import logging import time import json @@ -65,16 +64,6 @@ def _process_request(pipeline, request) -> Dict[str, Any]: start_time = time.time() params = request.params or {} - - # format global, top-level filters (e.g. "params": {"filters": {"name": ["some"]}}) - if "filters" in params.keys(): - params["filters"] = _format_filters(params["filters"]) - - # format targeted node filters (e.g. "params": {"Retriever": {"filters": {"value"}}}) - for key in params.keys(): - if isinstance(params[key], Mapping) and "filters" in params[key].keys(): - params[key]["filters"] = _format_filters(params[key]["filters"]) - result = pipeline.run(query=request.query, params=params, debug=request.debug) # Ensure answers and documents exist, even if they're empty lists @@ -87,39 +76,3 @@ def _process_request(pipeline, request) -> Dict[str, Any]: json.dumps({"request": request, "response": result, "time": f"{(time.time() - start_time):.2f}"}, default=str) ) return result - - -def _format_filters(filters): - """ - Adjust filters to compliant format: - Put filter values into a list and remove filters with null value. - """ - new_filters = {} - if filters is None: - logger.warning( - "Request with deprecated filter format ('\"filters\": null'). " - "Remove empty filters from params to be compliant with future versions" - ) - else: - for key, values in filters.items(): - if values is None: - logger.warning( - "Request with deprecated filter format ('%s: null'). " - "Remove null values from filters to be compliant with future versions", - key, - ) - continue - - if not isinstance(values, list): - logger.warning( - "Request with deprecated filter format ('%s': %s). " - "Change to '%s':[%s]' to be compliant with future versions", - key, - values, - key, - values, - ) - values = [values] - - new_filters[key] = values - return new_filters diff --git a/rest_api/test/test_rest_api.py b/rest_api/test/test_rest_api.py index 3a9680965..e96e9eb75 100644 --- a/rest_api/test/test_rest_api.py +++ b/rest_api/test/test_rest_api.py @@ -358,19 +358,6 @@ def test_query_with_filter_list(client): mocked_pipeline.run.assert_called_with(query=TEST_QUERY, params=params, debug=False) -def test_query_with_deprecated_filter_format(client): - request_params = {"TestRetriever": {"filters": {"test_key": "i_should_be_a_list"}}} - expected_params = {"TestRetriever": {"filters": {"test_key": ["i_should_be_a_list"]}}} - with mock.patch("rest_api.controller.search.query_pipeline") as mocked_pipeline: - # `run` must return a dictionary containing a `query` key - mocked_pipeline.run.return_value = {"query": TEST_QUERY} - response = client.post(url="/query", json={"query": TEST_QUERY, "params": request_params}) - assert 200 == response.status_code - # Ensure `run` was called with the expected parameters. In this case, - # `_format_filters` will fix the `filters` format within the params - mocked_pipeline.run.assert_called_with(query=TEST_QUERY, params=expected_params, debug=False) - - def test_query_with_no_documents_and_no_answers(client): with mock.patch("rest_api.controller.search.query_pipeline") as mocked_pipeline: # `run` must return a dictionary containing a `query` key