Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DP-3106] Add a way to fetch lists of domains and other search facets #3129

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

MatMoore
Copy link
Contributor

@MatMoore MatMoore commented Jan 30, 2024

Use the aggregateAcrossEntities graphQL query to retrieve lists of domains, tags and other search facets for a result set:

The response from aggregateAcrossEntities looks like this:

{
  "data": {
    "aggregateAcrossEntities": {
      "facets": [
        {
          "field": "domains",
          "displayName": "Domain",
          "aggregations": [
            {
              "value": "urn:li:domain:094dc54b-0ebc-40a6-a4cf-e1b75e8b8089",
              "count": 7,
              "entity": {
                "properties": {
                  "name": "Pet Adoptions"
                }
              }
            },
            {
              "value": "urn:li:domain:7186eeff-a860-4b0a-989f-69473a0c9c67",
              "count": 4,
              "entity": {
                "properties": {
                  "name": "E-Commerce"
                }
              }
            },
            {
              "value": "urn:li:domain:7d64d0fa-66c3-445c-83db-3a324723daf8",
              "count": 3,
              "entity": {
                "properties": {
                  "name": "Marketing"
                }
              }
            }
          ]
        }
      ]
    }
  },
  "extensions": {}
}

I've wrapped the response in a new FacetsResponse object.

facets = client.search_facets()
for option in facets.options('domains'):
  print(option.label)
  print(option.value)
  print(option.count)

This also includes methods for looking up an option by label.

By default, the search_facets returns all the possible options. To render a filtered set of options, pass in the query, filter, and result_types arguments, to match the search method:

facets = client.search_facets(query: "...", filters=[MultiSelectFilter(...)}, result_types=[...])

@MatMoore MatMoore force-pushed the dp-3106-facet-improvements branch 2 times, most recently from 035f06c to 0f7fb85 Compare January 30, 2024 13:42
@MatMoore MatMoore force-pushed the dp-3106-facet-improvements branch from 0f7fb85 to 98939b0 Compare January 30, 2024 13:45
@MatMoore MatMoore marked this pull request as ready for review January 30, 2024 13:47
@MatMoore MatMoore requested a review from a team January 30, 2024 13:47
@MatMoore MatMoore merged commit 8a2a1eb into main Jan 30, 2024
16 checks passed
@MatMoore MatMoore deleted the dp-3106-facet-improvements branch January 30, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants