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

addFacet() public method

Append a facet to the collection
public addFacet ( string $field, string $facetType, array $facetConfig, array $facetFilter = null ) : Collection
$field string Facet field.
$facetType string Facet type.
$facetConfig array Facet config params.
$facetFilter array Facet filter.
return Collection
    public function addFacet($field, $facetType, $facetConfig, $facetFilter = null)
    {
        $this->facets[$field] = ['type' => $facetType, 'filter' => $facetFilter, 'config' => $facetConfig];
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * Append facets used to select suggested attributes.
  *
  * @return \Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Attribute\DataProvider
  */
 private function prepareProductCollection()
 {
     foreach ($this->attributeCollection as $attribute) {
         $facetSize = $this->getResultsPageSize();
         $filterField = $this->getFilterField($attribute);
         $this->productCollection->addFacet($filterField, BucketInterface::TYPE_TERM, ['size' => $facetSize]);
     }
     return $this;
 }