diff --git a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/base.py b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/base.py index b146ed8aef..e8a56ebd0f 100644 --- a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/base.py +++ b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/base.py @@ -8,13 +8,7 @@ DataProductMetadata, TableMetadata, ) -from ..search_types import ( - FacetOption, - MultiSelectFilter, - ResultType, - SearchFacets, - SearchResponse, -) +from ..search_types import MultiSelectFilter, ResultType, SearchFacets, SearchResponse logger = logging.getLogger(__name__) diff --git a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/datahub_client.py b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/datahub_client.py index 9e4fbece63..c28e86a953 100644 --- a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/datahub_client.py +++ b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/datahub_client.py @@ -24,13 +24,7 @@ DataProductMetadata, TableMetadata, ) -from ...search_types import ( - FacetOption, - MultiSelectFilter, - ResultType, - SearchFacets, - SearchResponse, -) +from ...search_types import MultiSelectFilter, ResultType, SearchFacets, SearchResponse from ..base import BaseCatalogueClient, CatalogueError, ReferencedEntityMissing, logger from .search import SearchClient @@ -353,4 +347,4 @@ def search_facets( """ return self.search_client.search_facets( query=query, result_types=result_types, filters=filters - ).facets + ) diff --git a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/graphql/facets.graphql b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/graphql/facets.graphql new file mode 100644 index 0000000000..e9fa78ebbf --- /dev/null +++ b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/graphql/facets.graphql @@ -0,0 +1,41 @@ +query Facets( + $query: String! + $facets: [String!] + $types: [EntityType!] + $filters: [FacetFilterInput!] +) { + aggregateAcrossEntities( + input: { + types: $types + query: $query + facets: $facets + orFilters: [{ and: $filters }] + } + ) { + facets { + field + displayName + aggregations { + value + count + entity { + ... on Domain { + properties { + name + } + } + ... on Tag { + properties { + name + } + } + ... on GlossaryTerm { + properties { + name + } + } + } + } + } + } +} diff --git a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/search.py b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/search.py index 02a4bd93c1..9fc6c95d55 100644 --- a/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/search.py +++ b/python-libraries/data-platform-catalogue/data_platform_catalogue/client/datahub/search.py @@ -61,7 +61,7 @@ def search( try: response = self.graph.execute_graphql(self.search_query, variables) except GraphError as e: - raise Exception("Unable to execute search") from e + raise Exception("Unable to execute search query") from e page_results = [] response = response["searchAcrossEntities"] @@ -99,9 +99,23 @@ def search_facets( """ Returns facets that can be used to filter the search results. """ - return self.search( - query=query, result_types=result_types, filters=filters - ).facets + types = self._map_result_types(result_types) + formatted_filters = self._map_filters(filters) + + variables = { + "query": query, + "facets": [], + "types": types, + "filters": formatted_filters, + } + + try: + response = self.graph.execute_graphql(self.search_query, variables) + except GraphError as e: + raise Exception("Unable to execute facets query") from e + + response = response["aggregateAcrossEntities"] + return self._parse_facets(response.get("facets", [])) def _map_result_types(self, result_types: Sequence[ResultType]): """ diff --git a/python-libraries/data-platform-catalogue/tests/test_datahub_search.py b/python-libraries/data-platform-catalogue/tests/test_datahub_search.py index 5588e6d218..08ba95c176 100644 --- a/python-libraries/data-platform-catalogue/tests/test_datahub_search.py +++ b/python-libraries/data-platform-catalogue/tests/test_datahub_search.py @@ -356,11 +356,7 @@ def test_filter(searcher, mock_graph): def test_facets(searcher, mock_graph): datahub_response = { - "searchAcrossEntities": { - "start": 0, - "count": 10, - "total": 10, - "searchResults": [], + "aggregateAcrossEntities": { "facets": [ { "field": "_entityType",