コード例 #1
0
ファイル: Adapter.php プロジェクト: pavelnovitsky/magento2
 /**
  * {@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);
 }
コード例 #2
0
ファイル: Adapter.php プロジェクト: shabbirvividads/magento2
 /**
  * {@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);
 }
コード例 #3
0
ファイル: Adapter.php プロジェクト: Doability/magento2dev
 /**
  * {@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);
 }
コード例 #4
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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: MapperTest.php プロジェクト: vasiljok/magento2
 /**
  * @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);
 }
コード例 #7
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);
 }
コード例 #8
0
 /**
  * @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);
 }
コード例 #9
0
ファイル: Adapter.php プロジェクト: Doability/magento2dev
 /**
  * {@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);
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->mapper->buildQuery($request);
     $response = $this->executeQuery($query);
     return $this->responseFactory->create($response);
 }