Skip to content

Commit 3a8355a

Browse files
committed
FEATURE: Make index configuration possible by dimensioncombination or index
1 parent 42da595 commit 3a8355a

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

Classes/ElasticSearchClient.php

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

16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\ConfigurationException;
1617
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\DimensionsService;
1718
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexNameStrategyInterface;
1819
use Flowpack\ElasticSearch\Domain\Model\Client;
@@ -108,6 +109,7 @@ public function withDimensions(\Closure $closure, array $dimensionValues = []):
108109
*
109110
* @return string
110111
* @throws Exception
112+
* @throws ConfigurationException
111113
* @todo Add a contraints, if the system use content dimensions, the dimensionsHash MUST be set
112114
*/
113115
public function getIndexName(): string
@@ -122,12 +124,13 @@ public function getIndexName(): string
122124
/**
123125
* @return string
124126
* @throws Exception
127+
* @throws ConfigurationException
125128
*/
126129
public function getIndexNamePrefix(): string
127130
{
128131
$name = trim($this->indexNameStrategy->get());
129132
if ($name === '') {
130-
throw new Exception('Index name can not be null');
133+
throw new ConfigurationException('IndexNameStrategy ' . get_class($this->indexNameStrategy) . ' returned an empty index name', 1582538800);
131134
}
132135

133136
return $name;
@@ -140,6 +143,7 @@ public function getIndexNamePrefix(): string
140143
* @return \Flowpack\ElasticSearch\Domain\Model\Index
141144
* @throws Exception
142145
* @throws \Flowpack\ElasticSearch\Exception
146+
* @throws ConfigurationException
143147
*/
144148
public function getIndex(): Index
145149
{

Classes/Indexer/NodeIndexer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class NodeIndexer extends AbstractNodeIndexer implements BulkNodeIndexerInterfac
130130
*/
131131
protected $batchSize;
132132

133+
/**
134+
* @var array
135+
* @Flow\InjectConfiguration(package="Flowpack.ElasticSearch", path="indexes")
136+
*/
137+
protected $indexConfiguration;
138+
133139
/**
134140
* The current Elasticsearch bulk request, in the format required by http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
135141
*
@@ -163,6 +169,7 @@ public function setDimensions(array $dimensionsValues): void
163169
* Returns the index name to be used for indexing, with optional indexNamePostfix appended.
164170
*
165171
* @return string
172+
* @throws Exception\ConfigurationException
166173
* @throws Exception
167174
*/
168175
public function getIndexName(): string
@@ -192,11 +199,18 @@ public function setIndexNamePostfix(string $indexNamePostfix): void
192199
* @return Index
193200
* @throws Exception
194201
* @throws \Flowpack\ElasticSearch\Exception
202+
* @throws Exception\ConfigurationException
195203
*/
196204
public function getIndex(): Index
197205
{
198206
$index = $this->searchClient->findIndex($this->getIndexName());
199-
$index->setSettingsKey($this->searchClient->getIndexName());
207+
208+
$perDimensionConfiguration = $this->indexConfiguration[$this->searchClient->getBundle()][$this->searchClient->getIndexName()] ?? null;
209+
if ($perDimensionConfiguration !== null) {
210+
$index->setSettingsKey($this->searchClient->getIndexName());
211+
} else {
212+
$index->setSettingsKey($this->searchClient->getIndexNamePrefix());
213+
}
200214

201215
return $index;
202216
}
@@ -212,7 +226,7 @@ public function getIndex(): Index
212226
public function indexNode(NodeInterface $node, $targetWorkspaceName = null): void
213227
{
214228
if ($this->nodeTypeIndexingConfiguration->isIndexable($node->getNodeType()) === false) {
215-
$this->logger->debug(sprintf('NodeIndexer - Node "%s" (%s) skipped, Node Type is not allowed in the index.', $node->getContextPath(), $node->getNodeType()));
229+
$this->logger->debug(sprintf('NodeIndexer - Node "%s" (%s) skipped, Node Type is not allowed in the index.', $node->getContextPath(), $node->getNodeType()), LogEnvironment::fromMethodName(__METHOD__));
216230
return;
217231
}
218232

0 commit comments

Comments
 (0)