Skip to content

Commit d3ee983

Browse files
Merge pull request #234 from dfeyer/feature-disable-indexin-per-nodetype-or-namespace
FEATURE: Skip specific node type or namespace from indexing
2 parents 8f7d272 + 820e873 commit d3ee983

5 files changed

Lines changed: 111 additions & 0 deletions

File tree

Classes/Driver/Version5/Mapping/NodeTypeMappingBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* source code.
1515
*/
1616

17+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
1718
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractNodeTypeMappingBuilder;
1819
use Flowpack\ElasticSearch\Domain\Model\Index;
1920
use Flowpack\ElasticSearch\Domain\Model\Mapping;
@@ -32,6 +33,12 @@
3233
*/
3334
class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
3435
{
36+
/**
37+
* @var NodeTypeIndexingConfiguration
38+
* @Flow\Inject
39+
*/
40+
protected $nodeTypeIndexingConfiguration;
41+
3542
/**
3643
* Called by the Flow object framework after creating the object and resolving all dependencies.
3744
*
@@ -51,6 +58,7 @@ public function initializeObject($cause): void
5158
*
5259
* @param Index $index
5360
* @return MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
61+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
5462
*/
5563
public function buildMappingInformation(Index $index): MappingCollection
5664
{
@@ -64,6 +72,10 @@ public function buildMappingInformation(Index $index): MappingCollection
6472
continue;
6573
}
6674

75+
if ($this->nodeTypeIndexingConfiguration->isIndexable($nodeType) === false) {
76+
continue;
77+
}
78+
6779
$type = $index->findType($this->convertNodeTypeNameToMappingName($nodeTypeName));
6880
$mapping = new Mapping($type);
6981
$fullConfiguration = $nodeType->getFullConfiguration();

Classes/Indexer/NodeIndexer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\BulkIndexingError;
2525
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\MalformedBulkRequestError;
2626
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
27+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
2728
use Flowpack\ElasticSearch\Domain\Model\Document as ElasticSearchDocument;
2829
use Flowpack\ElasticSearch\Domain\Model\Index;
2930
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
@@ -132,6 +133,12 @@ class NodeIndexer extends AbstractNodeIndexer implements BulkNodeIndexerInterfac
132133
*/
133134
protected $bulkProcessing = false;
134135

136+
/**
137+
* @var NodeTypeIndexingConfiguration
138+
* @Flow\Inject
139+
*/
140+
protected $nodeTypeIndexingConfiguration;
141+
135142
/**
136143
* Returns the index name to be used for indexing, with optional indexNamePostfix appended.
137144
*
@@ -183,6 +190,11 @@ public function getIndex(): Index
183190
*/
184191
public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
185192
{
193+
if ($this->nodeTypeIndexingConfiguration->isIndexable($node->getNodeType()) === false) {
194+
$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)');
195+
return;
196+
}
197+
186198
$indexer = function (NodeInterface $node, $targetWorkspaceName = null) {
187199
$contextPath = $node->getContextPath();
188200

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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="defaultConfigurationPerNodeType", package="Neos.ContentRepository.Search")
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 ($this->settings === null || !is_array($this->settings)) {
37+
return true;
38+
}
39+
40+
if (isset($this->settings[$nodeType->getName()]['indexed'])) {
41+
return (bool)$this->settings[$nodeType->getName()]['indexed'];
42+
}
43+
44+
$nodeTypeParts = explode(':', $nodeType->getName());
45+
$namespace = reset($nodeTypeParts) . ':*';
46+
if (isset($this->settings[$namespace]['indexed'])) {
47+
return (bool)$this->settings[$namespace]['indexed'];
48+
}
49+
if (isset($this->settings['*']['indexed'])) {
50+
return (bool)$this->settings['*']['indexed'];
51+
}
52+
53+
return false;
54+
}
55+
}

Configuration/Settings.yaml

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

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,35 @@ changes the index alias.
7272
./flow nodeindex:cleanup
7373
```
7474
75+
### Advanced Configuration
76+
77+
By default the indexing processes all NodeTypes, but you can change this in your *Settings.yaml*:
78+
79+
```yaml
80+
Neos:
81+
ContentRepository:
82+
Search:
83+
defaultConfigurationPerNodeType:
84+
'*':
85+
indexed: true
86+
'Neos.Neos:FallbackNode':
87+
indexed: false
88+
'Neos.Neos:Shortcut':
89+
indexed: false
90+
'Neos.Neos:ContentCollection':
91+
indexed: false
92+
```
93+
94+
You need to explicitly configure the individual NodeTypes (this feature does not check the Super Type configuration).
95+
But you can use a special notation to configure a full namespace, `Acme.AcmeCom:*` will be applied for all node
96+
types in the `Acme.AcmeCom` namespace. The most specific configuration is used in this order:
97+
98+
- NodeType name (`Neos.Neos:Shortcut`)
99+
- Full namespace notation (`Neos.Neos:*`)
100+
- Catch all (`*`)
101+
75102
### Advanced Index Settings
103+
76104
If you need advanced settings you can define them in your *Settings.yaml*:
77105

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

0 commit comments

Comments
 (0)