Skip to content

Commit 5c64eb9

Browse files
Merge pull request #318 from daniellienert/feature/showindexablenodetypes
FEATURE: Add show indexable command
2 parents 8683403 + 9c5a6af commit 5c64eb9

5 files changed

Lines changed: 143 additions & 5 deletions

File tree

Classes/Command/NodeTypeCommandController.php

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

16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
1617
use Neos\ContentRepository\Domain\Model\NodeType;
1718
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
1819
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
@@ -35,6 +36,12 @@ class NodeTypeCommandController extends CommandController
3536
*/
3637
protected $nodeTypeManager;
3738

39+
/**
40+
* @Flow\Inject
41+
* @var NodeTypeIndexingConfiguration
42+
*/
43+
protected $nodeTypeIndexingConfiguration;
44+
3845
/**
3946
* Show node type configuration after applying all supertypes etc
4047
*
@@ -58,4 +65,20 @@ public function showCommand(string $nodeType = null): void
5865
}
5966
$this->output(Yaml::dump($configuration, 5, 2));
6067
}
68+
69+
/**
70+
* Shows a list of NodeTypes and if they are configured to be indexable or not
71+
*
72+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
73+
*/
74+
public function showIndexableConfigurationCommand(): void
75+
{
76+
$indexableConfiguration = $this->nodeTypeIndexingConfiguration->getIndexableConfiguration();
77+
$indexTable = [];
78+
foreach ($indexableConfiguration as $nodeTypeName => $value) {
79+
$indexTable[] = [$nodeTypeName, $value ? '<success>true</success>' : '<error>false</error>'];
80+
}
81+
82+
$this->output->outputTable($indexTable, ['NodeType', 'indexable']);
83+
}
6184
}

Classes/Service/NodeTypeIndexingConfiguration.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service;
35

46
/*
@@ -13,6 +15,7 @@
1315

1416
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
1517
use Neos\ContentRepository\Domain\Model\NodeType;
18+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
1619
use Neos\Flow\Annotations as Flow;
1720

1821
/**
@@ -26,12 +29,18 @@ final class NodeTypeIndexingConfiguration
2629
*/
2730
protected $settings;
2831

32+
/**
33+
* @Flow\Inject
34+
* @var NodeTypeManager
35+
*/
36+
protected $nodeTypeManager;
37+
2938
/**
3039
* @param NodeType $nodeType
3140
* @return bool
3241
* @throws Exception
3342
*/
34-
public function isIndexable(NodeType $nodeType)
43+
public function isIndexable(NodeType $nodeType): bool
3544
{
3645
if ($this->settings === null || !is_array($this->settings)) {
3746
return true;
@@ -52,4 +61,19 @@ public function isIndexable(NodeType $nodeType)
5261

5362
return false;
5463
}
64+
65+
/**
66+
* @return array
67+
* @throws Exception
68+
*/
69+
public function getIndexableConfiguration(): array
70+
{
71+
$nodeConfigurations = [];
72+
/** @var NodeType $nodeType */
73+
foreach ($this->nodeTypeManager->getNodeTypes(false) as $nodeType) {
74+
$nodeConfigurations[$nodeType->getName()] = $this->isIndexable($nodeType);
75+
}
76+
77+
return $nodeConfigurations;
78+
}
5579
}

Configuration/Testing/Settings.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ Neos:
1111
realtimeIndexing:
1212
enabled: false
1313

14+
defaultConfigurationPerNodeType:
15+
'*':
16+
indexed: true
17+
'Flowpack.ElasticSearch.ContentRepositoryAdaptor:Type1':
18+
indexed: false
19+
1420
Flowpack:
1521
ElasticSearch:
1622
ContentRepositoryAdaptor:
1723
command:
1824
useSubProcesses: false
25+

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ if during development, you only want to index a few nodes, you can use "limit"
7878

7979
./flow nodeindex:build --limit 20
8080

81-
8281
### Cleanup old indices
8382

8483
In order to remove old, non-used indices, you should use this command from time to time:
@@ -91,18 +90,22 @@ The following commands are meant to be used for debugging while configuring and
9190

9291
./flow nodeindexmapping:indices
9392

94-
Shows the mapping between the projects dimensions presets and the resultig index name.
93+
Shows the mapping between the projects dimensions presets and the resulting index name.
9594

9695
./flow nodeindexmapping:mapping
9796

9897
Shows the mapping created for the NodeTypes.
9998

99+
./flow nodetype: showIndexableConfiguration
100+
101+
Shows a list of NodeTypes and if they are configured to be indexable
102+
100103
./flow search:viewnode <nodeIdentifier>
101-
104+
102105
Shows all contents that are indexed fo a given node.
103106

104107
./flow search:fulltext
105-
108+
106109
Performs a fulltext search and displays the results.
107110

108111

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Service;
5+
6+
/*
7+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
8+
*
9+
* (c) Contributors of the Neos Project - www.neos.io
10+
*
11+
* This package is Open Source Software. For the full copyright and license
12+
* information, please view the LICENSE file which was distributed with this
13+
* source code.
14+
*/
15+
16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\NodeTypeIndexingConfiguration;
17+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
18+
use Neos\Flow\Tests\FunctionalTestCase;
19+
20+
class NodeTypeIndexingConfigurationTest extends FunctionalTestCase
21+
{
22+
23+
/**
24+
* @var NodeTypeManager
25+
*/
26+
protected $nodeTypeManager;
27+
28+
/**
29+
* @var NodeTypeIndexingConfiguration
30+
*/
31+
protected $nodeTypeIndexingConfiguration;
32+
33+
public function setUp(): void
34+
{
35+
parent::setUp();
36+
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
37+
$this->nodeTypeIndexingConfiguration = $this->objectManager->get(NodeTypeIndexingConfiguration::class);
38+
}
39+
40+
public function nodeTypeDataProvider(): array
41+
{
42+
return [
43+
'notIndexable' => [
44+
'nodeTypeName' => 'Flowpack.ElasticSearch.ContentRepositoryAdaptor:Type1',
45+
'expected' => false,
46+
],
47+
'indexable' => [
48+
'nodeTypeName' => 'Flowpack.ElasticSearch.ContentRepositoryAdaptor:Type2',
49+
'expected' => true,
50+
],
51+
];
52+
}
53+
54+
/**
55+
* @test
56+
* @dataProvider nodeTypeDataProvider
57+
*
58+
* @param string $nodeTypeName
59+
* @param bool $expected
60+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
61+
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
62+
*/
63+
public function isIndexable(string $nodeTypeName, bool $expected): void
64+
{
65+
self::assertEquals($expected, $this->nodeTypeIndexingConfiguration->isIndexable($this->nodeTypeManager->getNodeType($nodeTypeName)));
66+
}
67+
68+
/**
69+
* @test
70+
* @dataProvider nodeTypeDataProvider
71+
*
72+
* @param string $nodeTypeName
73+
* @param bool $expected
74+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
75+
*/
76+
public function getIndexableConfiguration(string $nodeTypeName, bool $expected): void
77+
{
78+
$indexableConfiguration = $this->nodeTypeIndexingConfiguration->getIndexableConfiguration();
79+
self::assertEquals($indexableConfiguration[$nodeTypeName], $expected);
80+
}
81+
}

0 commit comments

Comments
 (0)