Skip to content

Commit

Permalink
Use simpler query for facet information
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed Jan 30, 2024
1 parent 722cbf0 commit 98939b0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -353,4 +347,4 @@ def search_facets(
"""
return self.search_client.search_facets(
query=query, result_types=result_types, filters=filters
).facets
)
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 98939b0

Please sign in to comment.