algorithmRepository = $algorithmRepository; $this->entityStorageFactory = $entityStorageFactory; } /** * {@inheritdoc} */ public function build( RequestBucketInterface $bucket, array $dimensions, array $queryResult, DataProviderInterface $dataProvider ) { /** @var DynamicBucket $bucket */ $algorithm = $this->algorithmRepository->get($bucket->getMethod(), ['dataProvider' => $dataProvider]); $data = $algorithm->getItems($bucket, $dimensions, $this->getEntityStorage($queryResult)); $resultData = $this->prepareData($data); return $resultData; } /** * Extract Document ids * * @param array $queryResult * @return EntityStorage */ private function getEntityStorage(array $queryResult) { $ids = []; foreach ($queryResult['hits']['hits'] as $document) { $ids[] = $document['_id']; } return $this->entityStorageFactory->create($ids); } /** * Prepare result data * * @param array $data * @return array */ private function prepareData($data) { $resultData = []; foreach ($data as $value) { $from = is_numeric($value['from']) ? $value['from'] : '*'; $to = is_numeric($value['to']) ? $value['to'] : '*'; unset($value['from'], $value['to']); $rangeName = "{$from}_{$to}"; $resultData[$rangeName] = array_merge(['value' => $rangeName], $value); } return $resultData; } }