Smile\ElasticsuiteCatalog\Block\Navigation::addFacets PHP Method

addFacets() private method

Append facets to the search requests using the coverage rate defined in admin.
private addFacets ( ) : void
return void
    private function addFacets()
    {
        $productCollection = $this->getLayer()->getProductCollection();
        $countBySetId = $productCollection->getProductCountByAttributeSetId();
        $totalCount = $productCollection->getSize();
        foreach ($this->filterList->getFilters($this->_catalogLayer) as $filter) {
            try {
                $attribute = $filter->getAttributeModel();
                $facetCoverageRate = $attribute->getFacetMinCoverageRate();
                $attributeCountCandidates = array_sum(array_intersect_key($countBySetId, $attribute->getAttributeSetInfo()));
                $currentCoverageRate = $attributeCountCandidates / $totalCount * 100;
                if ($facetCoverageRate < $currentCoverageRate) {
                    $filter->addFacetToCollection();
                }
            } catch (\Exception $e) {
                $filter->addFacetToCollection();
            }
        }
    }