/** * {@inheritdoc} */ public function query(RequestInterface $request) { /** @var Select $query */ $query = $this->mapper->buildQuery($request); $documents = $this->executeQuery($query); $aggregations = $this->aggregationBuilder->build($request, $documents); $response = ['documents' => $documents, 'aggregations' => $aggregations]; return $this->responseFactory->create($response); }
/** * {@inheritdoc} */ 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); }
public function testQuery() { $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]]; $this->connectionAdapter->expects($this->at(0))->method('fetchAssoc')->will($this->returnValue($selectResult['documents'])); $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select)); $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0)); $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']); $response = $this->adapter->query($this->request); $this->assertEquals($selectResult, $response); }
public function testQuery() { $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]]; $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock(); $this->connectionAdapter->expects($this->once())->method('select')->willReturn($select); $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $this->temporaryStorage->expects($this->any())->method('storeDocumentsFromSelect')->willReturn($table); $this->connectionAdapter->expects($this->any())->method('fetchAssoc')->will($this->returnValue($selectResult['documents'])); $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select)); $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0)); $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']); $response = $this->adapter->query($this->request); $this->assertEquals($selectResult, $response); }
/** * {@inheritdoc} */ public function query(RequestInterface $request) { $query = $this->catalogSearchHelper->getEscapedQueryText(); $storeId = $this->storeManager->getStore()->getId(); $temporaryStorage = $this->temporaryStorageFactory->create(); $documents = []; $table = null; if (!$this->config->getApplicationID($storeId) || !$this->config->getAPIKey($storeId) || $this->config->isEnabledFrontEnd($storeId) === false || $this->config->makeSeoRequest($storeId) === '0' || $this->request->getControllerName() === 'category' && $this->config->replaceCategories($storeId) == false) { $query = $this->mapper->buildQuery($request); $table = $temporaryStorage->storeDocumentsFromSelect($query); $documents = $this->getDocuments($table); } else { $algolia_query = $query !== '__empty__' ? $query : ''; //If instant search is on, do not make a search query unless SEO request is set to 'Yes' if (!$this->config->isInstantEnabled($storeId) || $this->config->makeSeoRequest($storeId)) { $documents = $this->algoliaHelper->getSearchResult($algolia_query, $storeId); } $getDocumentMethod = 'getDocument21'; $storeDocumentsMethod = 'storeApiDocuments'; if (version_compare($this->config->getMagentoVersion(), '2.1.0', '<') === true) { $getDocumentMethod = 'getDocument20'; $storeDocumentsMethod = 'storeDocuments'; } $apiDocuments = array_map(function ($document) use($getDocumentMethod) { return $this->{$getDocumentMethod}($document); }, $documents); $table = $temporaryStorage->{$storeDocumentsMethod}($apiDocuments); } $aggregations = $this->aggregationBuilder->build($request, $table); $response = ['documents' => $documents, 'aggregations' => $aggregations]; return $this->responseFactory->create($response); }
public function testBuildWithoutPassedDocuments() { $documentIds = [1, 2]; $tableName = 'table_name'; $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); $select->expects($this->once())->method('from')->with($tableName, TemporaryStorage::FIELD_ENTITY_ID)->willReturnSelf(); $this->table->expects($this->once())->method('getName')->willReturn($tableName); $this->connectionMock->expects($this->once())->method('select')->willReturn($select); $this->connectionMock->expects($this->once())->method('fetchCol')->willReturn($documentIds); $this->aggregationResolver->expects($this->once())->method('resolve')->with($this->request, $documentIds)->willReturn([]); $this->builder->build($this->request, $this->table); }
/** * Test for method "build" */ public function testBuild() { $fetchResult = ['name' => ['some', 'result']]; $documents = [['product_id' => 1, 'sku' => 'Product']]; $this->bucket->expects($this->once())->method('getName')->willReturn('name'); $this->entityMetadata->expects($this->once())->method('getEntityId')->willReturn('product_id'); $this->request->expects($this->once())->method('getAggregation')->willReturn([$this->bucket]); $this->request->expects($this->once())->method('getDimensions')->willReturn([]); $this->bucketBuilder->expects($this->once())->method('build')->willReturn($fetchResult['name']); $result = $this->builder->build($this->request, $documents); $this->assertEquals($result, $fetchResult); }
/** * Test for method "build" */ public function testBuild() { $fetchResult = ['name' => ['some', 'result']]; /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */ $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $this->bucket->expects($this->once())->method('getName')->willReturn('name'); $this->request->expects($this->once())->method('getAggregation')->willReturn([$this->bucket]); $this->request->expects($this->once())->method('getDimensions')->willReturn([]); $this->bucketBuilder->expects($this->once())->method('build')->willReturn($fetchResult['name']); $result = $this->builder->build($this->request, $table); $this->assertEquals($result, $fetchResult); }
/** * {@inheritdoc} */ public function query(RequestInterface $request) { $query = $this->mapper->buildQuery($request); if ($request->getName() == 'quick_search_container') { $query->limit($this->searchConfig->getResultsLimit()); } if (isset($_GET) && isset($_GET['debug'])) { echo '<hr>' . $query . '<hr>'; } $temporaryStorage = $this->temporaryStorageFactory->create(); $table = $temporaryStorage->storeDocumentsFromSelect($query); $this->searchHelper->prepareTemporaryTable($table); $documents = $this->getDocuments($table); $aggregations = $this->aggregationBuilder->build($request, $table); $response = ['documents' => $documents, 'aggregations' => $aggregations]; return $this->responseFactory->create($response); }
/** * @param RequestInterface $request * @return \Magento\Framework\Search\Response\QueryResponse */ public function query(RequestInterface $request) { try { $query = $this->mapper->buildQuery($request); $query->limit($this->searchConfig->getResultsLimit()); } catch (\Exception $e) { // fallback engine $objectManager = ObjectManager::getInstance(); return $objectManager->create('Mirasvit\\SearchMysql\\Model\\Adapter')->query($request); } $temporaryStorage = $this->temporaryStorageFactory->create(); $table = $temporaryStorage->storeDocumentsFromSelect($query); $this->searchHelper->prepareTemporaryTable($table); $documents = $this->getDocuments($table); $aggregations = $this->aggregationBuilder->build($request, $table); $response = ['documents' => $documents, 'aggregations' => $aggregations]; return $this->responseFactory->create($response); }