11<?php
2- namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping ;
2+ namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \ Version1 \ Mapping ;
33
44/*
55 * This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
1111 * source code.
1212 */
1313
14+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \AbstractNodeTypeMappingBuilder ;
1415use Flowpack \ElasticSearch \Domain \Model \Index ;
1516use Flowpack \ElasticSearch \Domain \Model \Mapping ;
1617use Flowpack \ElasticSearch \Mapping \MappingCollection ;
1718use TYPO3 \Flow \Annotations as Flow ;
18- use TYPO3 \Flow \Configuration \ConfigurationManager ;
19+ use TYPO3 \Flow \Error \Result ;
20+ use TYPO3 \Flow \Error \Warning ;
1921use TYPO3 \TYPO3CR \Domain \Model \NodeType ;
20- use TYPO3 \TYPO3CR \Domain \Service \NodeTypeManager ;
2122
2223/**
23- * Builds the mapping information for TYPO3CR Node Types in Elastic Search
24+ * NodeTypeMappingBuilder for Elasticsearch version 1.x
2425 *
2526 * @Flow\Scope("singleton")
2627 */
27- class NodeTypeMappingBuilder
28+ class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
2829{
29- /**
30- * The default configuration for a given property type in NodeTypes.yaml, if no explicit elasticSearch section defined there.
31- *
32- * @var array
33- */
34- protected $ defaultConfigurationPerType ;
35-
36- /**
37- * @Flow\Inject
38- * @var NodeTypeManager
39- */
40- protected $ nodeTypeManager ;
41-
42- /**
43- * @var \TYPO3\Flow\Error\Result
44- */
45- protected $ lastMappingErrors ;
46-
47- /**
48- * @Flow\Inject
49- * @var ConfigurationManager
50- */
51- protected $ configurationManager ;
52-
53- /**
54- * Called by the Flow object framework after creating the object and resolving all dependencies.
55- *
56- * @param integer $cause Creation cause
57- */
58- public function initializeObject ($ cause )
59- {
60- if ($ cause === \TYPO3 \Flow \Object \ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
61- $ settings = $ this ->configurationManager ->getConfiguration (\TYPO3 \Flow \Configuration \ConfigurationManager::CONFIGURATION_TYPE_SETTINGS , 'TYPO3.TYPO3CR.Search ' );
62- $ this ->defaultConfigurationPerType = $ settings ['defaultConfigurationPerType ' ];
63- }
64- }
65-
66- /**
67- * Converts a TYPO3CR Node Type name into a name which can be used for an Elastic Search Mapping
68- *
69- * @param string $nodeTypeName
70- * @return string
71- */
72- public static function convertNodeTypeNameToMappingName ($ nodeTypeName )
73- {
74- return str_replace ('. ' , '- ' , $ nodeTypeName );
75- }
76-
7730 /**
7831 * Builds a Mapping Collection from the configured node types
7932 *
80- * @param \Flowpack\ElasticSearch\Domain\Model\ Index $index
81- * @return \Flowpack\ElasticSearch\Mapping\ MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
33+ * @param Index $index
34+ * @return MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
8235 */
8336 public function buildMappingInformation (Index $ index )
8437 {
85- $ this ->lastMappingErrors = new \ TYPO3 \ Flow \ Error \ Result ();
38+ $ this ->lastMappingErrors = new Result ();
8639
8740 $ mappings = new MappingCollection (MappingCollection::TYPE_ENTITY );
8841
@@ -99,7 +52,7 @@ public function buildMappingInformation(Index $index)
9952 $ mapping ->setFullMapping ($ fullConfiguration ['search ' ]['elasticSearchMapping ' ]);
10053 }
10154
102- // http ://www.elasticsearch.org /guide/en/elasticsearch/reference/current/mapping-root-object-type .html#_dynamic_templates
55+ // https ://www.elastic.co /guide/en/elasticsearch/reference/2.4/dynamic-templates .html
10356 // 'not_analyzed' is necessary
10457 $ mapping ->addDynamicTemplate ('dimensions ' , [
10558 'path_match ' => '__dimensionCombinations.* ' ,
@@ -124,7 +77,7 @@ public function buildMappingInformation(Index $index)
12477 $ mapping ->setPropertyByPath ($ propertyName , $ this ->defaultConfigurationPerType [$ propertyConfiguration ['type ' ]]['elasticSearchMapping ' ]);
12578 }
12679 } else {
127- $ this ->lastMappingErrors ->addWarning (new \ TYPO3 \ Flow \ Error \ Warning ('Node Type " ' . $ nodeTypeName . '" - property " ' . $ propertyName . '": No ElasticSearch Mapping found. ' ));
80+ $ this ->lastMappingErrors ->addWarning (new Warning ('Node Type " ' . $ nodeTypeName . '" - property " ' . $ propertyName . '": No ElasticSearch Mapping found. ' ));
12881 }
12982 }
13083
@@ -133,12 +86,4 @@ public function buildMappingInformation(Index $index)
13386
13487 return $ mappings ;
13588 }
136-
137- /**
138- * @return \TYPO3\Flow\Error\Result
139- */
140- public function getLastMappingErrors ()
141- {
142- return $ this ->lastMappingErrors ;
143- }
14489}
0 commit comments