/** * {@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); }
public function testCreate() { $rawResponse = ['documents' => [['title' => 'oneTitle', 'description' => 'oneDescription'], ['title' => 'twoTitle', 'description' => 'twoDescription']], 'aggregations' => []]; $this->documentFactory->expects($this->at(0))->method('create')->with($this->equalTo($rawResponse['documents'][0]))->will($this->returnValue('document1')); $this->documentFactory->expects($this->at(1))->method('create')->with($rawResponse['documents'][1])->will($this->returnValue('document2')); $this->objectManager->expects($this->once())->method('create')->with($this->equalTo('Magento\\Framework\\Search\\Response\\QueryResponse'), $this->equalTo(['documents' => ['document1', 'document2'], 'aggregations' => null]))->will($this->returnValue('QueryResponseObject')); $result = $this->factory->create($rawResponse); $this->assertEquals('QueryResponseObject', $result); }
/** * {@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); }
/** * {@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); }
/** * {@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); }
/** * {@inheritdoc} */ public function query(RequestInterface $request) { $query = $this->mapper->buildQuery($request); $response = $this->executeQuery($query); return $this->responseFactory->create($response); }