Skip to content

Commit 5c36e96

Browse files
committed
FEATURE: Skip specific node type or namespace from indexing
1 parent bc0c8f8 commit 5c36e96

5 files changed

Lines changed: 117 additions & 0 deletions

File tree

Classes/Indexer/NodeIndexer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\MalformedBulkRequestError;
2323
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
2424
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
25+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
2526
use Flowpack\ElasticSearch\Domain\Model\Document as ElasticSearchDocument;
2627
use Flowpack\ElasticSearch\Domain\Model\Index;
2728
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
@@ -121,6 +122,12 @@ class NodeIndexer extends AbstractNodeIndexer implements BulkNodeIndexerInterfac
121122
*/
122123
protected $bulkProcessing = false;
123124

125+
/**
126+
* @var NodeTypeIndexingConfiguration
127+
* @Flow\Inject
128+
*/
129+
protected $nodeTypeIndexingConfiguration;
130+
124131
/**
125132
* Returns the index name to be used for indexing, with optional indexNamePostfix appended.
126133
*
@@ -170,6 +177,11 @@ public function getIndex()
170177
*/
171178
public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
172179
{
180+
if ($this->nodeTypeIndexingConfiguration->isIndexable($node->getNodeType()) === false) {
181+
$this->logger->log(sprintf('NodeIndexer - Node "%s" (%s) skipped, Node Type is not allowed in the index.', $node->getContextPath(), $node->getNodeType()), LOG_DEBUG, null, 'ElasticSearch (CR)');
182+
return;
183+
}
184+
173185
$indexer = function (NodeInterface $node, $targetWorkspaceName = null) {
174186
$contextPath = $node->getContextPath();
175187

Classes/Mapping/NodeTypeMappingBuilder.php

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

14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
1415
use Flowpack\ElasticSearch\Domain\Model\Index;
1516
use Flowpack\ElasticSearch\Domain\Model\Mapping;
1617
use Flowpack\ElasticSearch\Mapping\MappingCollection;
@@ -50,6 +51,12 @@ class NodeTypeMappingBuilder
5051
*/
5152
protected $configurationManager;
5253

54+
/**
55+
* @var NodeTypeIndexingConfiguration
56+
* @Flow\Inject
57+
*/
58+
protected $nodeTypeIndexingConfiguration;
59+
5360
/**
5461
* Called by the Flow object framework after creating the object and resolving all dependencies.
5562
*
@@ -92,6 +99,10 @@ public function buildMappingInformation(Index $index)
9299
continue;
93100
}
94101

102+
if ($this->nodeTypeIndexingConfiguration->isIndexable($nodeType) === false) {
103+
continue;
104+
}
105+
95106
$type = $index->findType(self::convertNodeTypeNameToMappingName($nodeTypeName));
96107
$mapping = new Mapping($type);
97108
$fullConfiguration = $nodeType->getFullConfiguration();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service;
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\ContentRepositoryAdaptor\Exception;
15+
use Neos\ContentRepository\Domain\Model\NodeType;
16+
use Neos\Flow\Annotations as Flow;
17+
18+
/**
19+
* @Flow\Scope("singleton")
20+
*/
21+
final class NodeTypeIndexingConfiguration
22+
{
23+
/**
24+
* @var array
25+
* @Flow\InjectConfiguration(path="configuration")
26+
*/
27+
protected $settings;
28+
29+
/**
30+
* @param NodeType $nodeType
31+
* @return bool
32+
* @throws Exception
33+
*/
34+
public function isIndexable(NodeType $nodeType)
35+
{
36+
if (!isset($this->settings['nodeTypes'])) {
37+
return true;
38+
}
39+
40+
if (!\is_array($this->settings['nodeTypes'])) {
41+
throw new Exception('Check your configuration at indexingConfiguration.nodeTypes, this path must be an array', 1504721629);
42+
}
43+
44+
$settings = $this->settings['nodeTypes'];
45+
46+
if (isset($settings[$nodeType->getName()]['indexed'])) {
47+
return $settings[$nodeType->getName()]['indexed'];
48+
}
49+
50+
$nodeTypeParts = \explode(':', $nodeType->getName());
51+
$namespace = reset($nodeTypeParts) . ':*';
52+
if (isset($settings[$namespace]['indexed'])) {
53+
return $settings[$namespace]['indexed'];
54+
}
55+
if (isset($settings['*']['indexed'])) {
56+
return $settings['*']['indexed'];
57+
}
58+
59+
return false;
60+
}
61+
}

Configuration/Settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Flowpack:
33
ElasticSearch:
44
ContentRepositoryAdaptor:
5+
configuration:
6+
nodeTypes:
7+
'*':
8+
indexed: true
59
driver:
610
version: 1.x
711
mapping:

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,36 @@ changes the index alias.
6666
./flow nodeindex:cleanup
6767
```
6868

69+
### Advanced Configuration
70+
71+
By default the indexing process all Node Types, but you can change this configuration in your ```Settings.yaml```:
72+
73+
```
74+
Flowpack:
75+
ElasticSearch:
76+
ContentRepositoryAdaptor:
77+
configuration:
78+
nodeTypes:
79+
'*':
80+
indexed: true
81+
'Neos.Neos:FallbackNode':
82+
indexed: false
83+
'Neos.Neos:Shortcut':
84+
indexed: false
85+
'Neos.Neos:ContentCollection':
86+
indexed: false
87+
```
88+
89+
You need to configure explicitly the Node Types (this feature does not check the Super Type configuration). You
90+
can use a special notation to configuration a full name space, ```Neos.NodeTypes:*``` will be applied for all node
91+
types in the given namespace. The most specific configuration is used in this order:
92+
93+
- Node Type name (```Neos.Neos:Shortcut```)
94+
- Full namespace notation (```Neos.Neos:*```)
95+
- Catch all (```*```)
96+
6997
### Advanced Index Settings
98+
7099
If you need advanced settings you can define them in your *Settings.yaml*:
71100

72101
Example is from the Documentation of the used *Flowpack.ElasticSearch* Package

0 commit comments

Comments
 (0)