diff --git a/datagateway_api/src/search_api/filters.py b/datagateway_api/src/search_api/filters.py index 2786d0c2..d585db1e 100644 --- a/datagateway_api/src/search_api/filters.py +++ b/datagateway_api/src/search_api/filters.py @@ -49,12 +49,19 @@ def apply_filter(self, query): # matters): # {"Parameter": {"value": ["numericValue", "stringValue", "dateTimeValue"]}} # noqa: B950 if field_name == "value": - if isinstance(self.value, (int, float)): + # If the value is a list, extract the first value to determine which + # parameter value type should be used + if self.operation == "between" and isinstance(self.value, list): + filter_value = self.value[0] + else: + filter_value = self.value + + if isinstance(filter_value, (int, float)): icat_field_name = icat_field_name[0] - elif isinstance(self.value, datetime): + elif isinstance(filter_value, datetime): icat_field_name = icat_field_name[2] - elif isinstance(self.value, str): - if DateHandler.is_str_a_date(self.value): + elif isinstance(filter_value, str): + if DateHandler.is_str_a_date(filter_value): icat_field_name = icat_field_name[2] else: icat_field_name = icat_field_name[1] diff --git a/test/search_api/filters/test_search_api_where_filter.py b/test/search_api/filters/test_search_api_where_filter.py index f212b20c..5e2d8794 100644 --- a/test/search_api/filters/test_search_api_where_filter.py +++ b/test/search_api/filters/test_search_api_where_filter.py @@ -177,6 +177,14 @@ class TestSearchAPIWhereFilter: id="Numeric (float) parameter value (mapping that maps to multiple ICAT" "fields)", ), + pytest.param( + SearchAPIWhereFilter("parameters.value", [20, 30], "between"), + "Document", + "SELECT o FROM Investigation o JOIN o.parameters AS p WHERE" + " p.numericValue between '20' and '30'", + id="Numeric (int) parameter value with between operator (mapping that" + " maps to multiple ICAT fields)", + ), pytest.param( SearchAPIWhereFilter("parameters.value", ["test"], "eq"), "Document",