Skip to content

Commit 35255c6

Browse files
committed
TASK: Merge branch '3.0'
# Conflicts: # .travis.yml # Classes/Command/NodeIndexCommandController.php # Classes/Driver/Version1/Mapping/NodeTypeMappingBuilder.php # Classes/Indexer/NodeIndexer.php # Configuration/Settings.yaml # Configuration/Testing/NodeTypes.yaml # README.md # composer.json
2 parents e262634 + aaafca4 commit 35255c6

30 files changed

Lines changed: 900 additions & 39 deletions

.travis.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
language: php
2+
sudo: false
3+
git:
4+
depth: 5
5+
submodules: false
6+
addons:
7+
apt:
8+
packages:
9+
- oracle-java8-set-default
210
matrix:
311
include:
412
- php: 7.0
513
env: ES=1
614
- php: 7.0
715
env: ES=2
16+
<<<<<<< HEAD
817
- php: 7.1
18+
=======
19+
- php: 7.0
20+
env: ES=5
21+
- php: 5.6
22+
>>>>>>> 3.0
923
env: ES=1
1024
- php: 7.1
1125
env: ES=2
12-
sudo: false
26+
- php: 5.6
27+
env: ES=5
1328
before_install:
29+
<<<<<<< HEAD
1430
- export NEOS_TARGET_VERSION=3.0
31+
=======
32+
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
33+
- export NEOS_TARGET_VERSION=2.3
34+
>>>>>>> 3.0
1535
- cd ..
1636
- if [ "$ES" = 1 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.6.zip && unzip elasticsearch-1.7.6.zip && mv elasticsearch-1.7.6 elasticsearch; fi
17-
- if [ "$ES" = 2 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.4.5.zip && unzip elasticsearch-2.4.5.zip && mv elasticsearch-2.4.5 elasticsearch; fi
37+
- if [ "$ES" = 2 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.4.6.zip && unzip elasticsearch-2.4.6.zip && mv elasticsearch-2.4.6 elasticsearch; fi
38+
- if [ "$ES" = 5 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.zip && unzip elasticsearch-5.6.8.zip && mv elasticsearch-5.6.8 elasticsearch; fi
1839
- cd elasticsearch
1940
- bin/elasticsearch -d
2041
- cd ..
@@ -31,3 +52,4 @@ script:
3152
- bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Unit
3253
- if [ "$ES" = 1 ]; then FLOW_CONTEXT="Testing/ElasticVersion1" bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional; fi
3354
- if [ "$ES" = 2 ]; then FLOW_CONTEXT="Testing/ElasticVersion2" bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional; fi
55+
- if [ "$ES" = 5 ]; then FLOW_CONTEXT="Testing/ElasticVersion5" bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional; fi

Classes/Command/NodeIndexCommandController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1717
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
1818
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
19+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
1920
use Flowpack\ElasticSearch\Domain\Model\Mapping;
2021
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
2122
use Neos\ContentRepository\Domain\Factory\NodeFactory;
@@ -79,7 +80,7 @@ class NodeIndexCommandController extends CommandController
7980

8081
/**
8182
* @Flow\Inject
82-
* @var NodeTypeMappingBuilder
83+
* @var NodeTypeMappingBuilderInterface
8384
*/
8485
protected $nodeTypeMappingBuilder;
8586

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Annotations as Flow;
15+
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
16+
use Neos\Flow\Error;
17+
use Neos\Flow\Configuration\ConfigurationManager;
18+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
19+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
20+
21+
/**
22+
* Builds the mapping information for Content Repository Node Types in Elasticsearch
23+
*
24+
* @Flow\Scope("singleton")
25+
*/
26+
abstract class AbstractNodeTypeMappingBuilder implements NodeTypeMappingBuilderInterface
27+
{
28+
/**
29+
* The default configuration for a given property type in NodeTypes.yaml, if no explicit elasticSearch section defined there.
30+
*
31+
* @var array
32+
*/
33+
protected $defaultConfigurationPerType;
34+
35+
/**
36+
* @Flow\Inject
37+
* @var NodeTypeManager
38+
*/
39+
protected $nodeTypeManager;
40+
41+
/**
42+
* @Flow\Inject
43+
* @var ConfigurationManager
44+
*/
45+
protected $configurationManager;
46+
47+
/**
48+
* Called by the Flow object framework after creating the object and resolving all dependencies.
49+
*
50+
* @param integer $cause Creation cause
51+
* @throws InvalidConfigurationTypeException
52+
*/
53+
public function initializeObject($cause)
54+
{
55+
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
56+
$settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
57+
$this->defaultConfigurationPerType = $settings['defaultConfigurationPerType'];
58+
}
59+
}
60+
61+
/**
62+
* Converts a Content Repository Node Type name into a name which can be used for an Elasticsearch Mapping
63+
*
64+
* @param string $nodeTypeName
65+
* @return string
66+
*/
67+
public static function convertNodeTypeNameToMappingName($nodeTypeName)
68+
{
69+
return str_replace('.', '-', $nodeTypeName);
70+
}
71+
72+
73+
public function getLastMappingErrors()
74+
{
75+
return $this->lastMappingErrors;
76+
}
77+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Flowpack\ElasticSearch\Domain\Model\Index;
15+
use Flowpack\ElasticSearch\Mapping\MappingCollection;
16+
use Neos\Flow\Error\Result;
17+
18+
/**
19+
* NodeTypeMappingBuilder Interface
20+
*/
21+
interface NodeTypeMappingBuilderInterface
22+
{
23+
24+
/**
25+
* Converts a Content Repository Node Type name into a name which can be used for an Elasticsearch Mapping
26+
*
27+
* @param string $nodeTypeName
28+
* @return string
29+
*/
30+
public static function convertNodeTypeNameToMappingName($nodeTypeName);
31+
32+
/**
33+
* Builds a Mapping Collection from the configured node types
34+
*
35+
* @param Index $index
36+
* @return MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
37+
*/
38+
public function buildMappingInformation(Index $index);
39+
40+
/**
41+
* @return Result
42+
*/
43+
public function getLastMappingErrors();
44+
}

Classes/Driver/Version1/DocumentDriver.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractDriver;
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DocumentDriverInterface;
16-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
17+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
1718
use Flowpack\ElasticSearch\Domain\Model\Index;
1819
use Neos\ContentRepository\Domain\Model\NodeInterface;
1920
use Neos\ContentRepository\Domain\Model\NodeType;
@@ -26,15 +27,22 @@
2627
*/
2728
class DocumentDriver extends AbstractDriver implements DocumentDriverInterface
2829
{
30+
/**
31+
* @Flow\Inject
32+
* @var NodeTypeMappingBuilderInterface
33+
*/
34+
protected $nodeTypeMappingBuilder;
35+
2936
/**
3037
* {@inheritdoc}
3138
*/
3239
public function delete(NodeInterface $node, $identifier)
3340
{
41+
$nodeTypeMappingBuilder = $this->nodeTypeMappingBuilder;
3442
return [
3543
[
3644
'delete' => [
37-
'_type' => NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($node->getNodeType()),
45+
'_type' => $nodeTypeMappingBuilder::convertNodeTypeNameToMappingName($node->getNodeType()),
3846
'_id' => $identifier
3947
]
4048
]
@@ -46,6 +54,8 @@ public function delete(NodeInterface $node, $identifier)
4654
*/
4755
public function deleteDuplicateDocumentNotMatchingType(Index $index, $documentIdentifier, NodeType $nodeType)
4856
{
57+
$nodeTypeMappingBuilder = $this->nodeTypeMappingBuilder;
58+
4959
$index->request('DELETE', '/_query', [], json_encode([
5060
'query' => [
5161
'bool' => [
@@ -56,7 +66,7 @@ public function deleteDuplicateDocumentNotMatchingType(Index $index, $documentId
5666
],
5767
'must_not' => [
5868
'term' => [
59-
'_type' => NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType->getName())
69+
'_type' => $nodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType->getName())
6070
]
6171
],
6272
]

Classes/Driver/Version1/IndexerDriver.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractIndexerDriver;
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\IndexerDriverInterface;
16-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
1717
use Flowpack\ElasticSearch\Domain\Model\Document as ElasticSearchDocument;
1818
use Neos\ContentRepository\Domain\Model\NodeInterface;
1919
use Neos\Flow\Annotations as Flow;
@@ -25,6 +25,12 @@
2525
*/
2626
class IndexerDriver extends AbstractIndexerDriver implements IndexerDriverInterface
2727
{
28+
/**
29+
* @Flow\Inject
30+
* @var NodeTypeMappingBuilderInterface
31+
*/
32+
protected $nodeTypeMappingBuilder;
33+
2834
/**
2935
* {@inheritdoc}
3036
*/
@@ -96,10 +102,11 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
96102

97103
$this->logger->log(sprintf('NodeIndexer (%s): Updated fulltext index for %s (%s)', $closestFulltextNodeDocumentIdentifier, $closestFulltextNodeContextPath, $closestFulltextNode->getIdentifier()), LOG_DEBUG, null, 'ElasticSearch (CR)');
98104

105+
$nodeTypeMappingBuilder = $this->nodeTypeMappingBuilder;
99106
return [
100107
[
101108
'update' => [
102-
'_type' => NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($closestFulltextNode->getNodeType()->getName()),
109+
'_type' => $nodeTypeMappingBuilder::convertNodeTypeNameToMappingName($closestFulltextNode->getNodeType()->getName()),
103110
'_id' => $closestFulltextNodeDocumentIdentifier
104111
]
105112
],

Classes/Mapping/NodeTypeMappingBuilder.php renamed to Classes/Driver/Version1/Mapping/NodeTypeMappingBuilder.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -11,20 +11,22 @@
1111
* source code.
1212
*/
1313

14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractNodeTypeMappingBuilder;
1415
use Flowpack\ElasticSearch\Domain\Model\Index;
1516
use Flowpack\ElasticSearch\Domain\Model\Mapping;
1617
use Flowpack\ElasticSearch\Mapping\MappingCollection;
1718
use Neos\ContentRepository\Domain\Model\NodeType;
1819
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
20+
use Neos\Error\Messages\Result;
1921
use Neos\Flow\Annotations as Flow;
2022
use Neos\Flow\Configuration\ConfigurationManager;
2123

2224
/**
25+
* NodeTypeMappingBuilder for Elasticsearch version 1.x
2326
* Builds the mapping information for ContentRepository Node Types in Elasticsearch
24-
*
2527
* @Flow\Scope("singleton")
2628
*/
27-
class NodeTypeMappingBuilder
29+
class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
2830
{
2931
/**
3032
* The default configuration for a given property type in NodeTypes.yaml, if no explicit elasticSearch section defined there.
@@ -40,7 +42,7 @@ class NodeTypeMappingBuilder
4042
protected $nodeTypeManager;
4143

4244
/**
43-
* @var \Neos\Error\Messages\Result
45+
* @var Result
4446
*/
4547
protected $lastMappingErrors;
4648

@@ -77,12 +79,12 @@ public static function convertNodeTypeNameToMappingName($nodeTypeName)
7779
/**
7880
* Builds a Mapping Collection from the configured node types
7981
*
80-
* @param \Flowpack\ElasticSearch\Domain\Model\Index $index
81-
* @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
82+
* @param Index $index
83+
* @return MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
8284
*/
8385
public function buildMappingInformation(Index $index)
8486
{
85-
$this->lastMappingErrors = new \Neos\Error\Messages\Result();
87+
$this->lastMappingErrors = new Result();
8688

8789
$mappings = new MappingCollection(MappingCollection::TYPE_ENTITY);
8890

@@ -99,7 +101,7 @@ public function buildMappingInformation(Index $index)
99101
$mapping->setFullMapping($fullConfiguration['search']['elasticSearchMapping']);
100102
}
101103

102-
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates
104+
// https://www.elastic.co/guide/en/elasticsearch/reference/2.4/dynamic-templates.html
103105
// 'not_analyzed' is necessary
104106
$mapping->addDynamicTemplate('dimensions', [
105107
'path_match' => '__dimensionCombinations.*',
@@ -135,7 +137,7 @@ public function buildMappingInformation(Index $index)
135137
}
136138

137139
/**
138-
* @return \Neos\Error\Messages\Result
140+
* @return Result
139141
*/
140142
public function getLastMappingErrors()
141143
{

Classes/Driver/Version2/DocumentDriver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* source code.
1212
*/
1313

14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
1415
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version1;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1616
use Flowpack\ElasticSearch\Domain\Model\Index;
1717
use Neos\ContentRepository\Domain\Model\NodeType;
1818
use Neos\Flow\Annotations as Flow;
@@ -24,11 +24,19 @@
2424
*/
2525
class DocumentDriver extends Version1\DocumentDriver
2626
{
27+
/**
28+
* @Flow\Inject
29+
* @var NodeTypeMappingBuilderInterface
30+
*/
31+
protected $nodeTypeMappingBuilder;
32+
2733
/**
2834
* {@inheritdoc}
2935
*/
3036
public function deleteDuplicateDocumentNotMatchingType(Index $index, $documentIdentifier, NodeType $nodeType)
3137
{
38+
$nodeTypeMappingBuilder = $this->nodeTypeMappingBuilder;
39+
3240
$result = $index->request('GET', '/_search?scroll=1m', [], json_encode([
3341
'sort' => ['_doc'],
3442
'query' => [
@@ -40,7 +48,7 @@ public function deleteDuplicateDocumentNotMatchingType(Index $index, $documentId
4048
],
4149
'must_not' => [
4250
'term' => [
43-
'_type' => NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType->getName())
51+
'_type' => $nodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType->getName())
4452
]
4553
]
4654
]

0 commit comments

Comments
 (0)