mapper = $mapper; $this->responseFactory = $responseFactory; $this->resource = $resource; $this->aggregationBuilder = $aggregationBuilder; $this->temporaryStorageFactory = $temporaryStorageFactory; } /** * @inheritdoc * @throws \LogicException */ public function query(RequestInterface $request) { $query = $this->mapper->buildQuery($request); $temporaryStorage = $this->temporaryStorageFactory->create(); $table = $temporaryStorage->storeDocumentsFromSelect($query); $documents = $this->getDocuments($table); $aggregations = $this->aggregationBuilder->build($request, $table, $documents); $response = [ 'documents' => $documents, 'aggregations' => $aggregations, ]; return $this->responseFactory->create($response); } /** * Executes query and return raw response * * @param Table $table * @return array * @throws \Zend_Db_Exception */ private function getDocuments(Table $table) { $connection = $this->getConnection(); $select = $connection->select(); $select->from($table->getName(), ['entity_id', 'score']); return $connection->fetchAssoc($select); } /** * Get connection. * * @return false|\Magento\Framework\DB\Adapter\AdapterInterface */ private function getConnection() { return $this->resource->getConnection(); } }