Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
IndexStructure Class Reference
Inheritance diagram for IndexStructure:
IndexStructureInterface

Public Member Functions

 __construct (ResourceConnection $resource, IndexScopeResolver $indexScopeResolver, FlatScopeResolver $flatScopeResolver, array $columnTypesMap=[])
 
 delete ($index, array $dimensions=[])
 
 create ($index, array $fields, array $dimensions=[])
 

Protected Member Functions

 createFulltextIndex ($tableName)
 
 configureFulltextTable (Table $table)
 
 createFlatIndex ($tableName, array $fields)
 

Protected Attributes

 $columnTypesMap
 

Detailed Description

Full text search index structure.

Deprecated:
See also
\Magento\ElasticSearch

Definition at line 22 of file IndexStructure.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resource,
IndexScopeResolver  $indexScopeResolver,
FlatScopeResolver  $flatScopeResolver,
array  $columnTypesMap = [] 
)
Parameters
ResourceConnection$resource
IndexScopeResolver$indexScopeResolver
\Magento\Framework\Indexer\ScopeResolver\FlatScopeResolver$flatScopeResolver
array$columnTypesMap

Definition at line 54 of file IndexStructure.php.

59  {
60  $this->resource = $resource;
61  $this->indexScopeResolver = $indexScopeResolver;
62  $this->flatScopeResolver = $flatScopeResolver;
63  $this->columnTypesMap = array_merge($this->columnTypesMap, $columnTypesMap);
64  }

Member Function Documentation

◆ configureFulltextTable()

configureFulltextTable ( Table  $table)
protected

Configure full text index table.

Parameters
Table$table
Returns
Table

Definition at line 105 of file IndexStructure.php.

106  {
107  $table->addColumn(
108  'entity_id',
110  10,
111  ['unsigned' => true, 'nullable' => false],
112  'Entity ID'
113  )->addColumn(
114  'attribute_id',
116  255,
117  ['unsigned' => true, 'nullable' => true]
118  )->addColumn(
119  'data_index',
121  '4g',
122  ['nullable' => true],
123  'Data index'
124  )->addIndex(
125  'idx_primary',
126  ['entity_id', 'attribute_id'],
128  )->addIndex(
129  'FTI_FULLTEXT_DATA_INDEX',
130  ['data_index'],
132  );
133  return $table;
134  }
$table
Definition: trigger.php:14

◆ create()

create (   $index,
array  $fields,
array  $dimensions = [] 
)

Parameters
string$index
array$fields
Dimension[]$dimensions
Returns
void

Implements IndexStructureInterface.

Definition at line 78 of file IndexStructure.php.

79  {
80  $this->createFulltextIndex($this->indexScopeResolver->resolve($index, $dimensions));
81  if ($fields) {
82  $this->createFlatIndex($this->flatScopeResolver->resolve($index, $dimensions), $fields);
83  }
84  }
$fields
Definition: details.phtml:14
createFlatIndex($tableName, array $fields)
$index
Definition: list.phtml:44

◆ createFlatIndex()

createFlatIndex (   $tableName,
array  $fields 
)
protected

Create flat index.

Parameters
string$tableName
array$fields
Exceptions

Definition at line 144 of file IndexStructure.php.

145  {
146  $table = $this->resource->getConnection()->newTable($tableName);
147  $table->addColumn(
148  'entity_id',
150  10,
151  ['unsigned' => true, 'nullable' => false],
152  'Entity ID'
153  );
154  foreach ($fields as $field) {
155  if ($field['type'] !== 'filterable') {
156  continue;
157  }
158  $columnMap = isset($field['dataType']) && isset($this->columnTypesMap[$field['dataType']])
159  ? $this->columnTypesMap[$field['dataType']]
160  : ['type' => $field['type'], 'size' => isset($field['size']) ? $field['size'] : null];
161  $name = $field['name'];
162  $type = $columnMap['type'];
163  $size = $columnMap['size'];
164  $table->addColumn($name, $type, $size);
165  }
166  $this->resource->getConnection()->createTable($table);
167  }
$tableName
Definition: trigger.php:13
$fields
Definition: details.phtml:14
$type
Definition: item.phtml:13
$table
Definition: trigger.php:14
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ createFulltextIndex()

createFulltextIndex (   $tableName)
protected

Create full text index.

Parameters
string$tableName
Exceptions

Definition at line 93 of file IndexStructure.php.

94  {
95  $table = $this->configureFulltextTable($this->resource->getConnection()->newTable($tableName));
96  $this->resource->getConnection()->createTable($table);
97  }
$tableName
Definition: trigger.php:13
$table
Definition: trigger.php:14

◆ delete()

delete (   $index,
array  $dimensions = [] 
)

Parameters
string$index
Dimension[]$dimensions
Returns
void

Implements IndexStructureInterface.

Definition at line 69 of file IndexStructure.php.

70  {
71  $this->dropTable($this->resource->getConnection(), $this->indexScopeResolver->resolve($index, $dimensions));
72  $this->dropTable($this->resource->getConnection(), $this->flatScopeResolver->resolve($index, $dimensions));
73  }
$index
Definition: list.phtml:44

Field Documentation

◆ $columnTypesMap

$columnTypesMap
protected
Initial value:
= [
'varchar' => ['type' => Table::TYPE_TEXT, 'size' => 255],
'mediumtext' => ['type' => Table::TYPE_TEXT, 'size' => 16777216],
'text' => ['type' => Table::TYPE_TEXT, 'size' => 65536],
]

Definition at line 42 of file IndexStructure.php.


The documentation for this class was generated from the following file: