11<?php
2-
32declare (strict_types=1 );
43
54namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \Version6 \Mapping ;
2322use Neos \Error \Messages \Result ;
2423use Neos \Error \Messages \Warning ;
2524use Neos \Flow \Annotations as Flow ;
26- use Neos \Flow \Configuration \Exception \InvalidConfigurationTypeException ;
27- use Neos \Flow \ObjectManagement \ObjectManagerInterface ;
2825
2926/**
30- * NodeTypeMappingBuilder for Elasticsearch version 5.x
31- *
3227 * @Flow\Scope("singleton")
3328 */
3429class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
@@ -39,20 +34,6 @@ class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
3934 */
4035 protected $ nodeTypeIndexingConfiguration ;
4136
42- /**
43- * Called by the Flow object framework after creating the object and resolving all dependencies.
44- *
45- * @param integer $cause Creation cause
46- * @throws InvalidConfigurationTypeException
47- */
48- public function initializeObject ($ cause ): void
49- {
50- parent ::initializeObject ($ cause );
51-
52- if ($ cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
53- $ this ->migrateConfigurationForElasticVersion6 ($ this ->defaultConfigurationPerType );
54- }
55- }
5637
5738 /**
5839 * Builds a Mapping Collection from the configured node types
@@ -82,15 +63,13 @@ public function buildMappingInformation(Index $index): MappingCollection
8263 $ fullConfiguration = $ nodeType ->getFullConfiguration ();
8364 if (isset ($ fullConfiguration ['search ' ]['elasticSearchMapping ' ])) {
8465 $ fullMapping = $ fullConfiguration ['search ' ]['elasticSearchMapping ' ];
85- $ this ->migrateConfigurationForElasticVersion6 ($ fullMapping );
8666 $ mapping ->setFullMapping ($ fullMapping );
8767 }
8868
8969 foreach ($ nodeType ->getProperties () as $ propertyName => $ propertyConfiguration ) {
9070 if (isset ($ propertyConfiguration ['search ' ]['elasticSearchMapping ' ])) {
9171 if (is_array ($ propertyConfiguration ['search ' ]['elasticSearchMapping ' ])) {
9272 $ propertyMapping = $ propertyConfiguration ['search ' ]['elasticSearchMapping ' ];
93- $ this ->migrateConfigurationForElasticVersion6 ($ propertyMapping );
9473 $ mapping ->setPropertyByPath ($ propertyName , $ propertyMapping );
9574 }
9675 } elseif (isset ($ propertyConfiguration ['type ' ], $ this ->defaultConfigurationPerType [$ propertyConfiguration ['type ' ]]['elasticSearchMapping ' ])) {
@@ -107,61 +86,4 @@ public function buildMappingInformation(Index $index): MappingCollection
10786
10887 return $ mappings ;
10988 }
110-
111- /**
112- * @param array $mapping
113- * @return void
114- */
115- protected function migrateConfigurationForElasticVersion6 (array &$ mapping ): void
116- {
117- $ this ->adjustStringTypeMapping ($ mapping );
118- }
119-
120- /**
121- * Adjust the mapping for string to text or keyword as needed.
122- *
123- * This is used to ease moving from ES 1.x and 2.x to 5.x by migrating the
124- * mapping like this:
125- *
126- * | 2.x | 5.x |
127- * |-------------------------------------------|----------------------------------|
128- * | "type": "string", "index": "no" | "type": "text", "index": false |
129- * | "type": "string", "index": "analyzed" | "type": "text", "index": true |
130- * | "type": "string", "index": "not_analyzed" | "type": "keyword", "index": true |
131- *
132- * @param array &$mapping
133- * @return void
134- */
135- protected function adjustStringTypeMapping (array &$ mapping ): void
136- {
137- $ adjustStringTypeMapping = function (&$ item ) {
138- if (isset ($ item ['type ' ]) && $ item ['type ' ] === 'string ' ) {
139- if (isset ($ item ['index ' ])) {
140- if ($ item ['index ' ] === 'not_analyzed ' ) {
141- $ item ['type ' ] = 'keyword ' ;
142- $ item ['index ' ] = true ;
143- unset($ item ['analyzer ' ]);
144- } elseif ($ item ['index ' ] === 'no ' ) {
145- $ item ['type ' ] = 'text ' ;
146- $ item ['index ' ] = false ;
147- } elseif ($ item ['index ' ] === 'analyzed ' ) {
148- $ item ['type ' ] = 'text ' ;
149- $ item ['index ' ] = true ;
150- }
151- } else {
152- $ item ['type ' ] = 'keyword ' ;
153- $ item ['index ' ] = true ;
154- }
155- }
156- };
157-
158- $ adjustStringTypeMapping ($ mapping );
159-
160- foreach ($ mapping as &$ item ) {
161- if (is_array ($ item )) {
162- $ adjustStringTypeMapping ($ mapping );
163- $ this ->adjustStringTypeMapping ($ item );
164- }
165- }
166- }
16789}
0 commit comments