/** * @param string $index * @param array $fields * @param Dimension[] $dimensions * @return void */ public function create($index, array $fields, array $dimensions = []) { $this->createFulltextIndex($this->indexScopeResolver->resolve($index, $dimensions)); if ($fields) { $this->createFlatIndex($this->flatScopeResolver->resolve($index, $dimensions), $fields); } }
public function testCreateWithEmptyFields() { $index = 'index_name'; $expectedTable = 'index_name_scope3_scope5_scope1'; $dimensions = ['index_name_scope_3' => $this->createDimensionMock('scope', 3), 'index_name_scope_5' => $this->createDimensionMock('scope', 5), 'index_name_scope_1' => $this->createDimensionMock('scope', 1)]; $position = 0; $this->indexScopeResolver->expects($this->once())->method('resolve')->with($index, $dimensions)->willReturn($expectedTable); $this->mockFulltextTable($position, $expectedTable, true); $this->target->create($index, [], $dimensions); }
/** * @param string $indexName * @param Dimension[] $dimensions * @param string $expected * @dataProvider resolveDataProvider */ public function testResolve($indexName, array $dimensions, $expected) { $dimensions = array_map(function ($demension) { return $this->createDimension($demension[0], $demension[1]); }, $dimensions); $scope = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $scope->expects($this->any())->method('getId')->willReturn(1); $this->resource->expects($this->once())->method('getTableName')->willReturnArgument(0); $this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope); $result = $this->target->resolve($indexName, $dimensions); $this->assertEquals($expected, $result); }
/** * Build index query * * @param RequestInterface $request * @return Select */ public function build(RequestInterface $request) { $searchIndexTable = $this->scopeResolver->resolve($request->getIndex(), $request->getDimensions()); $select = $this->resource->getConnection()->select()->from(['search_index' => $searchIndexTable], ['entity_id' => 'entity_id'])->joinLeft(['cea' => $this->resource->getTableName('catalog_eav_attribute')], 'search_index.attribute_id = cea.attribute_id', []); $select = $this->tableMapper->addTables($select, $request); $select = $this->processDimensions($request, $select); $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE); if ($isShowOutOfStock === false) { $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.entity_id = stock_index.product_id' . $this->resource->getConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), []); $select->where('stock_index.stock_status = ?', 1); } return $select; }
public function testCreateWithEmptyFields() { $fields = [['name' => 'fieldName1', 'type' => 'fieldType1', 'size' => 'fieldSize1'], ['name' => 'fieldName2', 'type' => 'fieldType2', 'size' => 'fieldSize2'], ['name' => 'fieldName3', 'type' => 'fieldType3', 'size' => 'fieldSize3'], ['name' => 'fieldName3', 'dataType' => 'varchar', 'type' => 'text', 'size' => '255'], ['name' => 'fieldName3', 'dataType' => 'mediumtext', 'type' => 'text', 'size' => '16777216'], ['name' => 'fieldName3', 'dataType' => 'text', 'type' => 'text', 'size' => '65536']]; $index = 'index_name'; $expectedTable = 'index_name_scope3_scope5_scope1'; $dimensions = ['index_name_scope_3' => $this->createDimensionMock('scope', 3), 'index_name_scope_5' => $this->createDimensionMock('scope', 5), 'index_name_scope_1' => $this->createDimensionMock('scope', 1)]; $position = 0; $this->indexScopeResolver->expects($this->once())->method('resolve')->with($index, $dimensions)->willReturn($expectedTable); $this->flatScopeResolver->expects($this->once())->method('resolve')->with($index, $dimensions)->willReturn($index . '_flat'); $position = $this->mockFulltextTable($position, $expectedTable, true); $this->mockFlatTable($position, $index . '_flat'); $this->target->create($index, $fields, $dimensions); }
/** * {@inheritdoc} */ public function build(RequestInterface $request) { $searchIndexTable = $this->scopeResolver->resolve($request->getIndex(), $request->getDimensions()); $select = $this->getSelect()->from(['search_index' => $searchIndexTable], ['entity_id' => 'entity_id'])->joinLeft(['tmp' => new \Zend_Db_Expr('(SELECT 1 as search_weight)')], '1=1', ''); return $select; }
/** * Index name by store id * * @param int $storeId * @return string */ public function getIndexName($storeId) { $dimension = new Dimension('scope', $storeId); return $this->indexScopeResolver->resolve($this->index->getCode(), [$dimension]); }
/** * @param string $index * @param Dimension[] $dimensions * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function resolve($index, array $dimensions) { return $this->indexScopeResolver->resolve($index, []) . self::SUFFIX_FLAT; }