Exemplo n.º 1
0
 /**
  * {@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);
 }
Exemplo n.º 2
0
 /**
  * {@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);
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 /**
  * {@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);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 /**
  * {@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);
 }
Exemplo n.º 7
0
 /**
  * {@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);
 }
Exemplo n.º 8
0
 /**
  * @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);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->mapper->buildQuery($request);
     $response = $this->executeQuery($query);
     return $this->responseFactory->create($response);
 }