-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add support for excluding NodeTypes from indexing
Resolves: Flowpack#45
- Loading branch information
1 parent
5b62c98
commit 4a068d7
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Flowpack\SimpleSearch\ContentRepositoryAdaptor\Service; | ||
|
||
/* | ||
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeType; | ||
use Neos\ContentRepository\Domain\Service\NodeTypeManager; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
final class NodeTypeIndexingConfiguration | ||
{ | ||
/** | ||
* @var array | ||
* @Flow\InjectConfiguration(path="defaultConfigurationPerNodeType", package="Neos.ContentRepository.Search") | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var NodeTypeManager | ||
*/ | ||
protected $nodeTypeManager; | ||
|
||
/** | ||
* @param NodeType $nodeType | ||
* @return bool | ||
*/ | ||
public function isIndexable(NodeType $nodeType): bool | ||
{ | ||
if ($this->settings === null || !is_array($this->settings)) { | ||
return true; | ||
} | ||
|
||
if (isset($this->settings[$nodeType->getName()]['indexed'])) { | ||
return (bool)$this->settings[$nodeType->getName()]['indexed']; | ||
} | ||
|
||
$nodeTypeParts = explode(':', $nodeType->getName()); | ||
$namespace = reset($nodeTypeParts) . ':*'; | ||
if (isset($this->settings[$namespace]['indexed'])) { | ||
return (bool)$this->settings[$namespace]['indexed']; | ||
} | ||
if (isset($this->settings['*']['indexed'])) { | ||
return (bool)$this->settings['*']['indexed']; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function getIndexableConfiguration(): array | ||
{ | ||
$nodeConfigurations = []; | ||
/** @var NodeType $nodeType */ | ||
foreach ($this->nodeTypeManager->getNodeTypes(false) as $nodeType) { | ||
$nodeConfigurations[$nodeType->getName()] = $this->isIndexable($nodeType); | ||
} | ||
|
||
return $nodeConfigurations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'Flowpack.SimpleSearch.ContentRepositoryAdaptor:BaseType': | ||
superTypes: { } | ||
'Flowpack.SimpleSearch.ContentRepositoryAdaptor:Type1': | ||
superTypes: | ||
'Flowpack.SimpleSearch.ContentRepositoryAdaptor:BaseType': true | ||
'Flowpack.SimpleSearch.ContentRepositoryAdaptor:Type2': | ||
superTypes: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Neos: | ||
ContentRepository: | ||
Search: | ||
realtimeIndexing: | ||
enabled: false | ||
defaultConfigurationPerNodeType: | ||
'*': | ||
indexed: true | ||
'Flowpack.SimpleSearch.ContentRepositoryAdaptor:Type1': | ||
indexed: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Tests/Functional/Service/NodeTypeIndexingConfigurationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Flowpack\SimpleSearch\ContentRepositoryAdaptor\Tests\Functional\Service; | ||
|
||
/* | ||
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Flowpack\SimpleSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration; | ||
use Neos\ContentRepository\Domain\Service\NodeTypeManager; | ||
use Neos\Flow\Tests\FunctionalTestCase; | ||
|
||
class NodeTypeIndexingConfigurationTest extends FunctionalTestCase | ||
{ | ||
|
||
/** | ||
* @var NodeTypeManager | ||
*/ | ||
protected $nodeTypeManager; | ||
|
||
/** | ||
* @var NodeTypeIndexingConfiguration | ||
*/ | ||
protected $nodeTypeIndexingConfiguration; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); | ||
$this->nodeTypeIndexingConfiguration = $this->objectManager->get(NodeTypeIndexingConfiguration::class); | ||
} | ||
|
||
public function nodeTypeDataProvider(): array | ||
{ | ||
return [ | ||
'notIndexable' => [ | ||
'nodeTypeName' => 'Flowpack.SimpleSearch.ContentRepositoryAdaptor:Type1', | ||
'expected' => false, | ||
], | ||
'indexable' => [ | ||
'nodeTypeName' => 'Flowpack.SimpleSearch.ContentRepositoryAdaptor:Type2', | ||
'expected' => true, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider nodeTypeDataProvider | ||
* | ||
* @param string $nodeTypeName | ||
* @param bool $expected | ||
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException | ||
*/ | ||
public function isIndexable(string $nodeTypeName, bool $expected): void | ||
{ | ||
self::assertEquals($expected, $this->nodeTypeIndexingConfiguration->isIndexable($this->nodeTypeManager->getNodeType($nodeTypeName))); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider nodeTypeDataProvider | ||
* | ||
* @param string $nodeTypeName | ||
* @param bool $expected | ||
*/ | ||
public function getIndexableConfiguration(string $nodeTypeName, bool $expected): void | ||
{ | ||
$indexableConfiguration = $this->nodeTypeIndexingConfiguration->getIndexableConfiguration(); | ||
self::assertEquals($indexableConfiguration[$nodeTypeName], $expected); | ||
} | ||
} |