Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection::getFacetedData PHP Method

getFacetedData() public method

Return field faceted data from faceted search result.
public getFacetedData ( string $field ) : array
$field string Facet field.
return array
    public function getFacetedData($field)
    {
        $this->_renderFilters();
        $result = [];
        $aggregations = $this->queryResponse->getAggregations();
        $bucket = $aggregations->getBucket($field);
        if ($bucket) {
            foreach ($bucket->getValues() as $value) {
                $metrics = $value->getMetrics();
                $result[$metrics['value']] = $metrics;
            }
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  */
 public function getItems()
 {
     $items = [];
     foreach ($this->attributeCollection as $attribute) {
         $filterField = $this->getFilterField($attribute);
         $facetData = $this->productCollection->getFacetedData($filterField);
         foreach ($facetData as $currentFilter) {
             if ($currentFilter['value'] != '__other_docs') {
                 $currentFilter['attribute_code'] = $attribute->getAttributeCode();
                 $currentFilter['attribute_label'] = $attribute->getStoreLabel();
                 $currentFilter['type'] = $this->getType();
                 $items[] = $this->itemFactory->create($currentFilter);
             }
         }
     }
     uasort($items, [$this, 'resultSorterCallback']);
     return array_slice($items, 0, $this->getResultsPageSize());
 }