/** * {@inheritdoc} */ public function query(RequestInterface $request) { /** @var Select $query */ $query = $this->mapper->buildQuery($request); $response = ['documents' => $this->executeDocuments($query), 'aggregations' => $this->executeAggregations($query)]; return $this->responseFactory->create($response); }
/** * {@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); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Unknown query type 'unknownQuery' */ public function testGetUnknownQueryType() { $query = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\QueryInterface')->setMethods(['getType'])->disableOriginalConstructor()->getMockForAbstractClass(); $query->expects($this->exactly(2))->method('getType')->will($this->returnValue('unknownQuery')); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $this->mapper->buildQuery($this->request); }
/** * {@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); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Unknown query type 'unknownQuery' */ public function testGetUnknownQueryType() { $select = $this->createSelectMock(null, false, false); $this->mockBuilders($select); $query = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\QueryInterface')->setMethods(['getType'])->disableOriginalConstructor()->getMockForAbstractClass(); $query->expects($this->exactly(2))->method('getType')->will($this->returnValue('unknownQuery')); $this->connectionAdapter->expects($this->never())->method('select'); $this->connectionAdapter->expects($this->never())->method('dropTable'); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $this->mapper->buildQuery($this->request); }
/** * {@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); }
/** * {@inheritdoc} */ public function query(RequestInterface $request) { $query = $this->mapper->buildQuery($request); $response = $this->executeQuery($query); return $this->responseFactory->create($response); }