123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Search\Adapter\Mysql;
- use Magento\Framework\App\ResourceConnection;
- use Magento\Framework\DB\Ddl\Table;
- use Magento\Framework\Search\Adapter\Mysql\Aggregation\Builder as AggregationBuilder;
- use Magento\Framework\Search\AdapterInterface;
- use Magento\Framework\Search\RequestInterface;
- /**
- * MySQL Search Adapter
- *
- * @deprecated 102.0.0
- * @see \Magento\ElasticSearch
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class Adapter implements AdapterInterface
- {
- /**
- * Mapper instance
- *
- * @var Mapper
- */
- protected $mapper;
- /**
- * Response Factory
- *
- * @var ResponseFactory
- */
- protected $responseFactory;
- /**
- * @var \Magento\Framework\App\ResourceConnection
- */
- private $resource;
- /**
- * @var AggregationBuilder
- */
- private $aggregationBuilder;
- /**
- * @var TemporaryStorageFactory
- */
- private $temporaryStorageFactory;
- /**
- * @param Mapper $mapper
- * @param ResponseFactory $responseFactory
- * @param ResourceConnection $resource
- * @param AggregationBuilder $aggregationBuilder
- * @param TemporaryStorageFactory $temporaryStorageFactory
- */
- public function __construct(
- Mapper $mapper,
- ResponseFactory $responseFactory,
- ResourceConnection $resource,
- AggregationBuilder $aggregationBuilder,
- TemporaryStorageFactory $temporaryStorageFactory
- ) {
- $this->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();
- }
- }
|