Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/01_Installation/02_Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Following steps are necessary during updating to newer versions.
## Upgrade to 2.1.0
- Added support for Symfony 7
- [Indexing] Added sort index for documents
- [Indexing] Improved indexing of field collections to prevent mapping conflicts when properties have the same name but different types
- Execute the following command to reindex all elements to be able to use all new features:
```bin/console generic-data-index:update:index -r```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ public function getIndexMapping(): array
if (!$fieldCollectionDefinition) {
continue;
}
$mapping[$allowedType] = [
'type' => AttributeType::NESTED,
'properties' => [],
];
foreach ($fieldCollectionDefinition->getFieldDefinitions() as $fieldDefinition) {
$fieldDefinitionAdapter = $this->getFieldDefinitionService()
->getFieldDefinitionAdapter($fieldDefinition);
if ($fieldDefinitionAdapter) {
$mapping[$fieldDefinition->getName()] = $fieldDefinitionAdapter->getIndexMapping();
$mapping[$allowedType]['properties'][$fieldDefinition->getName()] =
$fieldDefinitionAdapter->getIndexMapping();
}
}
}

// Add type mapping
$mapping['type'] = [
'type' => AttributeType::TEXT,
];

return [
'type' => AttributeType::NESTED,
'properties' => $mapping,
Expand All @@ -77,19 +77,20 @@ public function normalize(mixed $value): ?array

foreach ($items as $item) {
$type = $item->getType();
$fieldCollectionDefinition = $this->fieldCollectionDefinition->getByKey($item->getType());
$fieldCollectionDefinition = $this->fieldCollectionDefinition->getByKey($type);
if (!$fieldCollectionDefinition) {
continue;
}
$resultItem = ['type' => $type];
$resultItem = [];

foreach ($fieldCollectionDefinition->getFieldDefinitions() as $fieldDefinition) {
$getter = 'get' . ucfirst($fieldDefinition->getName());
$value = $item->$getter();
$resultItem[$fieldDefinition->getName()] = $this->fieldDefinitionService->normalizeValue(
$fieldDefinition,
$value
);
$resultItem[$type][$fieldDefinition->getName()] =
$this->fieldDefinitionService->normalizeValue(
$fieldDefinition,
$value
);
}

$resultItems[] = $resultItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ public function testGetSearchIndexMapping(): void
$adapter->setFieldCollectionDefinition($definitionResolverMock);
$mapping = $adapter->getIndexMapping();

$this->assertSame([
$this->assertSame(
[
'type' => AttributeType::NESTED,
'properties' => [
'type' => [
'type' => AttributeType::TEXT,
],
],
], $mapping
],
$mapping
);

}
Expand Down