diff --git a/datagateway_api/src/api_start_utils.py b/datagateway_api/src/api_start_utils.py index 34cbfe10..a56e61bc 100644 --- a/datagateway_api/src/api_start_utils.py +++ b/datagateway_api/src/api_start_utils.py @@ -152,8 +152,7 @@ def create_api_endpoints(flask_app, api, specs): # DataGateway API endpoints if Config.config.datagateway_api is not None: datagateway_api_spec = next( - (spec for spec in specs if spec.title == "DataGateway API"), - None, + (spec for spec in specs if spec.title == "DataGateway API"), None, ) try: backend_type = flask_app.config["TEST_BACKEND"] @@ -224,8 +223,7 @@ def create_api_endpoints(flask_app, api, specs): # Session endpoint session_endpoint_resource = session_endpoints( - backend, - client_pool=icat_client_pool, + backend, client_pool=icat_client_pool, ) api.add_resource( session_endpoint_resource, @@ -236,8 +234,7 @@ def create_api_endpoints(flask_app, api, specs): # Table specific endpoints instrument_facility_cycle_resource = instrument_facility_cycles_endpoint( - backend, - client_pool=icat_client_pool, + backend, client_pool=icat_client_pool, ) api.add_resource( instrument_facility_cycle_resource, @@ -247,8 +244,7 @@ def create_api_endpoints(flask_app, api, specs): datagateway_api_spec.path(resource=instrument_facility_cycle_resource, api=api) count_instrument_facility_cycle_res = count_instrument_facility_cycles_endpoint( - backend, - client_pool=icat_client_pool, + backend, client_pool=icat_client_pool, ) api.add_resource( count_instrument_facility_cycle_res, @@ -258,8 +254,7 @@ def create_api_endpoints(flask_app, api, specs): datagateway_api_spec.path(resource=count_instrument_facility_cycle_res, api=api) instrument_investigation_resource = instrument_investigation_endpoint( - backend, - client_pool=icat_client_pool, + backend, client_pool=icat_client_pool, ) api.add_resource( instrument_investigation_resource, @@ -270,8 +265,7 @@ def create_api_endpoints(flask_app, api, specs): datagateway_api_spec.path(resource=instrument_investigation_resource, api=api) count_instrument_investigation_res = count_instrument_investigation_endpoint( - backend, - client_pool=icat_client_pool, + backend, client_pool=icat_client_pool, ) api.add_resource( count_instrument_investigation_res, @@ -289,8 +283,7 @@ def create_api_endpoints(flask_app, api, specs): # Search API endpoints if Config.config.search_api is not None: search_api_spec = next( - (spec for spec in specs if spec.title == "Search API"), - None, + (spec for spec in specs if spec.title == "Search API"), None, ) search_api_extension = Config.config.search_api.extension search_api_entity_endpoints = { diff --git a/datagateway_api/src/datagateway_api/icat/filters.py b/datagateway_api/src/datagateway_api/icat/filters.py index 935b7d46..80dba767 100644 --- a/datagateway_api/src/datagateway_api/icat/filters.py +++ b/datagateway_api/src/datagateway_api/icat/filters.py @@ -7,7 +7,6 @@ IncludeFilter, LimitFilter, OrderFilter, - ScoringQueryFilter, SkipFilter, WhereFilter, ) @@ -57,22 +56,16 @@ def create_filter(self): elif self.operation == "ilike": self.field = f"UPPER({self.field})" where_filter = self.create_condition( - self.field, - "like", - f"UPPER('%{self.value}%')", + self.field, "like", f"UPPER('%{self.value}%')", ) elif self.operation == "nlike": where_filter = self.create_condition( - self.field, - "not like", - f"%{self.value}%", + self.field, "not like", f"%{self.value}%", ) elif self.operation == "nilike": self.field = f"UPPER({self.field})" where_filter = self.create_condition( - self.field, - "not like", - f"UPPER('%{self.value}%')", + self.field, "not like", f"UPPER('%{self.value}%')", ) elif self.operation == "lt": where_filter = self.create_condition(self.field, "<", self.value) @@ -110,9 +103,7 @@ def create_filter(self): where_filter = self.create_condition(self.field, "not in", self.value) elif self.operation == "between": where_filter = self.create_condition( - self.field, - "between", - f"'{self.value[0]}' and '{self.value[1]}'", + self.field, "between", f"'{self.value[0]}' and '{self.value[1]}'", ) elif self.operation == "regexp": where_filter = self.create_condition(self.field, "regexp", self.value) @@ -230,8 +221,7 @@ def apply_filter(self, query): PythonICATOrderFilter.join_specs[join_field_str] = "LEFT JOIN" log.debug( - "Setting query join specs: %s", - PythonICATOrderFilter.join_specs, + "Setting query join specs: %s", PythonICATOrderFilter.join_specs, ) try: query.setJoinSpecs(PythonICATOrderFilter.join_specs) diff --git a/datagateway_api/src/search_api/filters.py b/datagateway_api/src/search_api/filters.py index f3d20e5c..cdbf68c5 100644 --- a/datagateway_api/src/search_api/filters.py +++ b/datagateway_api/src/search_api/filters.py @@ -8,7 +8,7 @@ PythonICATLimitFilter, PythonICATSkipFilter, PythonICATWhereFilter, - ScoringQueryFilter + ScoringQueryFilter, ) from datagateway_api.src.search_api.models import PaNOSCAttribute from datagateway_api.src.search_api.panosc_mappings import mappings @@ -162,6 +162,7 @@ def __init__(self, limit_value): def apply_filter(self, query): return super().apply_filter(query.icat_query.query) + class SearchAPIScoringFilter(ScoringQueryFilter): def __init__(self, query_value): super().__init__(query_value) @@ -169,6 +170,7 @@ def __init__(self, query_value): def apply_filter(self, query): return + class SearchAPIIncludeFilter(PythonICATIncludeFilter): def __init__(self, included_filters, panosc_entity_name): self.included_filters = included_filters diff --git a/datagateway_api/src/search_api/helpers.py b/datagateway_api/src/search_api/helpers.py index 740bbad8..cc60dc7c 100644 --- a/datagateway_api/src/search_api/helpers.py +++ b/datagateway_api/src/search_api/helpers.py @@ -202,9 +202,7 @@ def get_files(entity_name, pid, filters): log.info("Getting files of dataset (PID: %s), using request's filters", pid) log.debug( - "Entity Name: %s, Filters: %s", - entity_name, - filters, + "Entity Name: %s, Filters: %s", entity_name, filters, ) filters.append(SearchAPIWhereFilter("dataset.pid", pid, "eq")) @@ -226,13 +224,10 @@ def get_files_count(entity_name, filters, pid): """ log.info( - "Getting number of files for dataset (PID: %s), using request's filters", - pid, + "Getting number of files for dataset (PID: %s), using request's filters", pid, ) log.debug( - "Entity Name: %s, Filters: %s", - entity_name, - filters, + "Entity Name: %s, Filters: %s", entity_name, filters, ) filters.append(SearchAPIWhereFilter("dataset.pid", pid, "eq")) diff --git a/datagateway_api/src/search_api/query_filter_factory.py b/datagateway_api/src/search_api/query_filter_factory.py index fd669d63..08ac4187 100644 --- a/datagateway_api/src/search_api/query_filter_factory.py +++ b/datagateway_api/src/search_api/query_filter_factory.py @@ -6,6 +6,7 @@ from datagateway_api.src.search_api.filters import ( SearchAPIIncludeFilter, SearchAPILimitFilter, + SearchAPIScoringFilter, SearchAPISkipFilter, SearchAPIWhereFilter, ) @@ -62,6 +63,9 @@ def get_query_filter(request_filter, entity_name=None, related_entity_name=None) elif filter_name == "skip": log.info("skip JSON object found") query_filters.append(SearchAPISkipFilter(filter_input)) + elif filter_name == "query": + log.info("query JSON object found") + query_filters.append(SearchAPIScoringFilter(filter_input)) else: raise FilterError( "No valid filter name given within filter query param:"