We have about ~400 facets, which can be returned within the ais-dynamic-widgets component. A typical search might display 15-20 facet widgets.
We’d like to display the top eg 5 facets, based on how represented they are in the result set - for example a brand
facet would be on 100% of the search result items, width
might be on 55%, material
20%, guarantee
10%. If we were limiting to 3 facets, in this example we’d show brand, width and material.
I’ve tried to cross-reference the facets and the search results using the transform-items
prop on ais-dynamic-widgets
, which can take the set of results in the form:
transformDynamicWidgetItems(items, { results }) {}
But the results (in results.disjunctiveFacets
) only gives the results for the current paginated set of results - which for us is 24 results out of potentially thousands.
I can foresee this will get us in a bind, as the most common facets for page 2 might not align with those for page1.
Though I can see how I might get this to work if I had access to the full result set, I can also see that it might have very poor performance.
Is there an out-of-the-box or best practice way to limit the number of facets shown to the top x?