How to use facets from Azure Cognitive Search in a Power App

Paul Summers
2 min readJan 6, 2021

--

Continuing my journey building a Power App on top of Azure Cognitive Search, this post provides some pointers and tips for configuring and retrieving facets with a custom connector in the Power Platform.

For GET operations with the Azure Cognitive Search REST API, if you need more than one facet, which is pretty standard for a search-driven application, you need to pass the facet query parameter for each facet you want returned. However, custom connectors do not support multiple query parameters with the same name. I tried manually updating the custom connector’s OpenAPI (Swagger) definition directly to accommodate this but could not find a way to allow for multiple parameters of the same name. Instead, the search API provides a POST operation that supports the facets parameter in the POST body, where you can specify a set of facets and their configurations in an array. Notice that the POST operation uses facets plural rather than facet singular, which is used for the GET operation.

Once I figured this out and added an action to my connector supporting the POST operation for search queries, the test capabilities in the Power Apps connector configuration were still failing because of how it was encoding the facets parameter. However, the connector configuration updated and otherwise validated correctly in the custom connector configuration wizard. When I tested it in my Power App, it worked as expected, returning the appropriate facets and facet filters.

In my formula calling the connector, I passed the facets parameter in as a table using the following syntax: facets:Table({Value:”modifiedBy"},{Value:"insuranceProvider"})

The full request looks like this:

UpdateContext(
{
searchResultsObjectPost: 'ProjectCortex-AzureSearch'.GetResultsPost({
'api-version': "2020-06-30",'Content-Type': "application/json",search: "*",count: "true",
facets: Table(
{Value: "modifiedBy"},
{Value: "insuranceProvider"}
)
})
});

There are a lot of additional query parameters that need to be accounted for but since facets provide a lot of capability to the search interface, I wanted to start there.

Up next, displaying the facets and applying the filters correctly as users select them.

--

--

Responses (1)