Just wondering if there is a way to not show faceted navigation in results interface if no facets are being returned. We have a few multiple-value metadata fields we use for content tagging, but they are optional so it’s likely many pages are empty for these fields. We’re seeing in search results the facet box (has a heading ‘Refine Search’) but because none of the pages returned have the metadata for these facets filled the facet box is empty. FacetedLabel macro seems to be true/false based on whether faceted search is configured or not, not on whether there’s any actual facets to display. Anyone know how to only show the facet box only if there’s facet options to display?
it should be possible to hide the complete panel if no facets are returned.
Try wrapping the <@s.FacetedSearch>
… </@s.FacetedSearch>
in a conditional that checks if there are any facets returned in the response of the data model. Something like:
<#if response.facets?exists>
<@s.FacetedSearch>
...
</@s.FacetedSearch>
</#if>
Note: I’m not currently in a position to check the exact conditional to use but it should be something like that (ie. may not be exists, but something like != “” etc)
Thanks Peter! (is this peter??)
Not quite as simple as you said but got me on the right track. The facets array comes back the same every time and is based solely on configuration, not the results. Drilling into the arrays there’s a categories sub-array that will be potentially empty based on the results. But you’ve got to check that sub-array is empty in every one of the facet array elements. This is what I came up with:
<#assign hasFacets = false>
<#list response.facets as facet>
<#if facet.categories?size gt 0>
<#assign hasFacets = true>
</#if>
</#list>
<#if hasFacets>
<@s.FacetedSearch>
....
</@s.FacetedSearch>
</#if>