Skip to content

Commit a55c094

Browse files
committed
TASK: Support dimension-less instances
1 parent 2b36b1e commit a55c094

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

Classes/Indexer/NodeIndexer.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,13 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null): voi
287287

288288
$workspaceName = $targetWorkspaceName ?: $node->getContext()->getWorkspaceName();
289289
$dimensionCombinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
290-
if ($dimensionCombinations !== []) {
290+
291+
if (array_filter($dimensionCombinations) === []) {
292+
$handleNode($node, $this->createContentContext($workspaceName));
293+
} else {
291294
foreach ($dimensionCombinations as $combination) {
292295
$handleNode($node, $this->createContentContext($workspaceName, $combination));
293296
}
294-
} else {
295-
$handleNode($node, $this->createContentContext($workspaceName));
296297
}
297298
}
298299

@@ -307,9 +308,11 @@ protected function createContentContext(string $workspaceName, array $dimensions
307308
'workspaceName' => $workspaceName,
308309
'invisibleContentShown' => true
309310
];
311+
310312
if ($dimensions !== []) {
311313
$configuration['dimensions'] = $dimensions;
312314
}
315+
313316
return $this->contextFactory->create($configuration);
314317
}
315318

@@ -390,7 +393,7 @@ public function removeNode(NodeInterface $node, string $targetWorkspaceName = nu
390393
*/
391394
protected function flushIfNeeded(): void
392395
{
393-
if ($this->bulkRequestLenght() >= $this->batchSize['elements'] || $this->bulkRequestSize() >= $this->batchSize['octets']) {
396+
if ($this->bulkRequestLength() >= $this->batchSize['elements'] || $this->bulkRequestSize() >= $this->batchSize['octets']) {
394397
$this->flush();
395398
}
396399
}
@@ -402,7 +405,10 @@ protected function bulkRequestSize(): int
402405
}, 0);
403406
}
404407

405-
protected function bulkRequestLenght(): int
408+
/**
409+
* @return int
410+
*/
411+
protected function bulkRequestLength(): int
406412
{
407413
return count($this->currentBulkRequest);
408414
}
@@ -418,7 +424,7 @@ protected function bulkRequestLenght(): int
418424
public function flush(): void
419425
{
420426
$bulkRequest = $this->currentBulkRequest;
421-
$bulkRequestSize = $this->bulkRequestLenght();
427+
$bulkRequestSize = $this->bulkRequestLength();
422428
if ($bulkRequestSize === 0) {
423429
return;
424430
}
@@ -442,9 +448,7 @@ public function flush(): void
442448

443449
foreach ($bulkRequestPart->getRequest() as $bulkRequestItem) {
444450
if ($bulkRequestItem === null) {
445-
$this->errorHandlingService->log(
446-
new MalformedBulkRequestError('Indexing Error: Bulk request item could not be encoded as JSON - ' . json_last_error_msg(), $bulkRequestItem)
447-
);
451+
$this->errorHandlingService->log(new MalformedBulkRequestError('Indexing Error: Bulk request item could not be encoded as JSON - ' . json_last_error_msg(), $bulkRequestItem));
448452
continue 2;
449453
}
450454
$payload[$hash][] = $bulkRequestItem;
@@ -462,10 +466,8 @@ public function flush(): void
462466
}
463467

464468
$this->searchClient->setDimensions($dimensions);
465-
466469
$response = $this->requestDriver->bulk($this->getIndex(), implode(chr(10), $payload[$hash]));
467470

468-
469471
foreach ($response as $responseLine) {
470472
if (isset($response['errors']) && $response['errors'] !== false) {
471473
$this->errorHandlingService->log(new BulkIndexingError($this->currentBulkRequest, $responseLine));
@@ -476,7 +478,7 @@ public function flush(): void
476478
$this->reset();
477479
}
478480

479-
protected function reset()
481+
protected function reset(): void
480482
{
481483
$this->dimensionService->reset();
482484
$this->currentBulkRequest = [];

Classes/Service/DimensionsService.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,33 @@ class DimensionsService
3232
*/
3333
protected $dimensionsRegistry = [];
3434

35-
public function hash(array $dimensionValues): ?string
35+
protected const HASH_DEFAULT = 'default';
36+
37+
/**
38+
* @param array $dimensionValues
39+
* @return string
40+
*/
41+
public function hash(array $dimensionValues): string
3642
{
3743
if ($dimensionValues === []) {
38-
return null;
44+
$this->dimensionsRegistry[self::HASH_DEFAULT] = [];
45+
return self::HASH_DEFAULT;
3946
}
47+
4048
$this->lastTargetDimensions = array_map(static function ($dimensionValues) {
4149
return [\is_array($dimensionValues) ? array_shift($dimensionValues) : $dimensionValues];
4250
}, $dimensionValues);
4351

4452
$hash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($this->lastTargetDimensions);
4553
$this->dimensionsRegistry[$hash] = $this->lastTargetDimensions;
54+
4655
return $hash;
4756
}
4857

58+
/**
59+
* @param NodeInterface $node
60+
* @return string|null
61+
*/
4962
public function hashByNode(NodeInterface $node): ?string
5063
{
5164
return $this->hash($node->getContext()->getTargetDimensions());
@@ -59,15 +72,7 @@ public function getDimensionsRegistry(): array
5972
return $this->dimensionsRegistry;
6073
}
6174

62-
/**
63-
* @return array
64-
*/
65-
public function getLastTargetDimensions(): array
66-
{
67-
return $this->lastTargetDimensions;
68-
}
69-
70-
public function reset()
75+
public function reset(): void
7176
{
7277
$this->dimensionsRegistry = [];
7378
$this->lastTargetDimensions = null;

0 commit comments

Comments
 (0)