Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexStructure.php
Go to the documentation of this file.
1 <?php
8 
16 
24 {
28  private $resource;
29 
33  private $indexScopeResolver;
34 
39  public function __construct(
40  ResourceConnection $resource,
41  IndexScopeResolverInterface $indexScopeResolver
42  ) {
43  $this->resource = $resource;
44  $this->indexScopeResolver = $indexScopeResolver;
45  }
46 
50  public function delete($index, array $dimensions = [])
51  {
52  $tableName = $this->indexScopeResolver->resolve($index, $dimensions);
53  if ($this->resource->getConnection()->isTableExists($tableName)) {
54  $this->resource->getConnection()->dropTable($tableName);
55  }
56  }
57 
61  public function create($index, array $fields, array $dimensions = [])
62  {
63  $this->createFulltextIndex($this->indexScopeResolver->resolve($index, $dimensions));
64  }
65 
73  protected function createFulltextIndex($tableName)
74  {
75  $table = $this->resource->getConnection()->newTable($tableName)
76  ->addColumn(
77  'entity_id',
79  10,
80  ['unsigned' => true, 'nullable' => false],
81  'Entity ID'
82  )->addColumn(
83  'attribute_id',
85  10,
86  ['unsigned' => true, 'nullable' => false]
87  )->addColumn(
88  'data_index',
90  '4g',
91  ['nullable' => true],
92  'Data index'
93  )->addIndex(
94  'idx_primary',
95  ['entity_id', 'attribute_id'],
97  )->addIndex(
98  'FTI_FULLTEXT_DATA_INDEX',
99  ['data_index'],
101  );
102  $this->resource->getConnection()->createTable($table);
103  }
104 }
$tableName
Definition: trigger.php:13
$fields
Definition: details.phtml:14
$resource
Definition: bulk.php:12
__construct(ResourceConnection $resource, IndexScopeResolverInterface $indexScopeResolver)
$table
Definition: trigger.php:14
$index
Definition: list.phtml:44
create($index, array $fields, array $dimensions=[])