Smile\ElasticsuiteCatalog\Model\ResourceModel\Eav\Indexer\Fulltext\Datasource\AbstractAttributeData::addIndexedFilterToAttributeCollection PHP Method

addIndexedFilterToAttributeCollection() public method

Allow to filter an attribute collection on attributes that are indexed into the search engine.
public addIndexedFilterToAttributeCollection ( Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection ) : Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
$attributeCollection Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection Attribute collection (not loaded).
return Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
    public function addIndexedFilterToAttributeCollection(AttributeCollection $attributeCollection)
    {
        $conditions = [];
        foreach ($this->indexedAttributesConditions as $fieldName => $condition) {
            if ($condition['operator'] == 'IN' || is_array($condition['value'])) {
                $conditionString = sprintf('%s %s (?)', $fieldName, $condition['operator']);
                $conditions[] = $this->connection->quoteInto($conditionString, $condition['value']);
            } elseif (!is_array($condition['value'])) {
                $conditions[] = sprintf('%s %s %s', $fieldName, $condition['operator'], $condition['value']);
            }
        }
        if (!empty($conditions)) {
            $select = $attributeCollection->getSelect();
            $select->where(implode(' OR ', $conditions));
        }
        return $attributeCollection;
    }

Usage Example

 /**
  * Init attributes used into ES.
  *
  * @return \Smile\ElasticsuiteCatalog\Model\Eav\Indexer\Fulltext\Datasource\AbstractAttributeData
  */
 private function initAttributes()
 {
     $attributeCollection = $this->attributeHelper->getAttributeCollection();
     $this->resourceModel->addIndexedFilterToAttributeCollection($attributeCollection);
     foreach ($attributeCollection as $attribute) {
         if ($this->canIndexAttribute($attribute)) {
             $attributeId = (int) $attribute->getId();
             $this->attributesById[$attributeId] = $attribute;
             $this->attributeIdsByTable[$attribute->getBackendTable()][] = $attributeId;
             $this->initField($attribute);
         }
     }
     return $this;
 }