dataProviderContainer = array_map( function (DataProviderInterface $dataProvider) { return $dataProvider; }, $dataProviderContainer ); $this->aggregationContainer = array_map( function (BucketBuilderInterface $bucketBuilder) { return $bucketBuilder; }, $aggregationContainer ); $this->dataProviderFactory = $dataProviderFactory ?: ObjectManager::getInstance()->get(DataProviderFactory::class); } /** * Builds aggregations from the search request. * * This method iterates through buckets and builds all aggregations one by one, passing buckets and relative * data into bucket aggregation builders which are responsible for aggregation calculation. * * @param RequestInterface $request * @param array $queryResult * @return array * @throws \LogicException thrown by DataProviderFactory for validation issues * @see \Magento\Elasticsearch\SearchAdapter\Aggregation\DataProviderFactory */ public function build(RequestInterface $request, array $queryResult) { $aggregations = []; $buckets = $request->getAggregation(); $dataProvider = $this->dataProviderFactory->create( $this->dataProviderContainer[$request->getIndex()], $this->query ); foreach ($buckets as $bucket) { $bucketAggregationBuilder = $this->aggregationContainer[$bucket->getType()]; $aggregations[$bucket->getName()] = $bucketAggregationBuilder->build( $bucket, $request->getDimensions(), $queryResult, $dataProvider ); } $this->query = null; return $aggregations; } /** * Sets the QueryContainer instance to the internal property in order to use it in build process * * @param QueryContainer $query * @return $this */ public function setQuery(QueryContainer $query) { $this->query = $query; return $this; } }