コード例 #1
0
 public function testStoreDocuments()
 {
     $documentId = 312432;
     $documentValue = 1.235123;
     $documentField = $this->getMockBuilder('Magento\\Framework\\Search\\DocumentField')->disableOriginalConstructor()->getMock();
     $documentField->expects($this->once())->method('getValue')->willReturn($documentValue);
     $document = $this->getMockBuilder('Magento\\Framework\\Search\\Document')->disableOriginalConstructor()->getMock();
     $document->expects($this->once())->method('getId')->willReturn($documentId);
     $document->expects($this->once())->method('getField')->with('score')->willReturn($documentField);
     $table = $this->createTemporaryTable();
     $result = $this->model->storeDocuments([$document]);
     $this->assertEquals($result, $table);
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: Mapper.php プロジェクト: pradeep-wagento/magento2
 /**
  * @param RequestInterface $request
  * @param Select $select
  * @param IndexBuilderInterface $indexBuilder
  * @param MatchContainer[] $matchQueries
  * @return Select
  */
 private function addMatchQueries(RequestInterface $request, Select $select, IndexBuilderInterface $indexBuilder, array $matchQueries)
 {
     $queriesCount = count($matchQueries);
     if ($queriesCount) {
         $table = $this->temporaryStorage->storeDocumentsFromSelect($select);
         foreach ($matchQueries as $matchContainer) {
             $queriesCount--;
             $matchScoreBuilder = $this->scoreBuilderFactory->create();
             $matchSelect = $this->matchBuilder->build($matchScoreBuilder, $indexBuilder->build($request), $matchContainer->getRequest(), $matchContainer->getConditionType());
             $select = $this->joinPreviousResultToSelect($matchSelect, $table, $matchScoreBuilder);
             if ($queriesCount) {
                 $previousResultTable = $table;
                 $table = $this->temporaryStorage->storeDocumentsFromSelect($select);
                 $this->getConnection()->dropTable($previousResultTable->getName());
             }
         }
     }
     return $select;
 }
コード例 #4
0
 /**
  * @param $query
  * @param array $derivedQueries
  * @param int $queriesCount
  * @throws \Exception
  * @dataProvider buildQueryDataProvider
  */
 public function testBuildQuery($query, array $derivedQueries = [], $queriesCount = 0)
 {
     $select = $this->createSelectMock(null, false, false);
     $this->mockBuilders($select);
     $previousSelect = $select;
     $selects = [];
     for ($i = $queriesCount; $i >= 0; $i--) {
         $isLast = $i === 0;
         $select = $this->createSelectMock($previousSelect, $isLast, true);
         $previousSelect = $select;
         $selects[] = $select;
     }
     $this->addSelects($selects);
     $this->request->expects($this->once())->method('getSize')->willReturn(self::REQUEST_LIMIT);
     $this->filterBuilder->expects($this->any())->method('build')->will($this->returnValue('(1)'));
     $table = $this->getMockBuilder('\\Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock();
     $this->temporaryStorage->expects($this->any())->method('storeDocumentsFromSelect')->willReturn($table);
     $table->expects($this->any())->method('getName')->willReturn('table_name');
     $this->queryContainer->expects($this->any())->method('getMatchQueries')->willReturn($derivedQueries);
     $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $response = $this->mapper->buildQuery($this->request);
     $this->assertEquals(end($selects), $response);
 }