/** * @inheritdoc */ public function getIndexMapping() { $model = $this->getModel(); /** @var \im\base\types\EntityTypesRegister $typesRegister */ $typesRegister = Yii::$app->get('typesRegister'); $entityType = $typesRegister->getEntityType($model); $indexableAttributes = IndexAttribute::findByIndexType($entityType); $searchableAttributes = $this->getSearchableAttributes(); $attributes = []; foreach ($indexableAttributes as $indexableAttribute) { foreach ($searchableAttributes as $searchableAttribute) { if ($indexableAttribute->name === $searchableAttribute->name) { $name = $searchableAttribute->name; if ($indexableAttribute->type) { $searchableAttribute->type = $indexableAttribute->type; } if ($indexableAttribute->index_name) { $searchableAttribute->name = $indexableAttribute->index_name; } $attributes[$name] = $searchableAttribute; } } } return $attributes; }
/** * Returns index attributes by type. * * @param string $type * @return IndexAttribute[] */ public function getIndexAttributes($type) { $searchableAttributes = $this->getSearchableAttributes($type); $indexAttributes = IndexAttribute::findByIndexType($type); $attributes = []; foreach ($searchableAttributes as $searchableAttribute) { /** @var IndexAttribute $indexAttribute */ $indexAttribute = null; foreach ($indexAttributes as $attribute) { if ($attribute->name === $searchableAttribute->name) { $indexAttribute = $attribute; break; } } if ($indexAttribute) { $indexAttribute->indexable = true; $indexAttribute->label = $searchableAttribute->label; } else { $indexAttribute = new IndexAttribute(['index_type' => $type, 'name' => $searchableAttribute->name, 'label' => $searchableAttribute->label]); } $attributes[] = $indexAttribute; } return $attributes; }