Skip to content

Commit 2ad9ba3

Browse files
committed
TASK: Simplify / clean up code
1 parent 019dd83 commit 2ad9ba3

6 files changed

Lines changed: 23 additions & 25 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ public function from($from): QueryBuilderInterface
237237
* add an exact-match query for a given property
238238
*
239239
* @param string $propertyName Name of the property
240-
* @param mixed $value Value for comparison
240+
* @param mixed $propertyValue Value for comparison
241241
* @return ElasticSearchQueryBuilder
242242
* @throws QueryBuildingException
243243
* @api
244244
*/
245-
public function exactMatch(string $propertyName, $value): QueryBuilderInterface
245+
public function exactMatch(string $propertyName, $propertyValue): QueryBuilderInterface
246246
{
247-
return $this->queryFilter('term', [$propertyName => $this->convertValue($value)]);
247+
return $this->queryFilter('term', [$propertyName => $this->convertValue($propertyValue)]);
248248
}
249249

250250
/**
@@ -613,8 +613,8 @@ public function fetch(): array
613613
protected function evaluateResult(array $result): SearchResult
614614
{
615615
return new SearchResult(
616-
$hits = $result['hits']['hits'] ?? [],
617-
$total = $result['hits']['total']['value'] ?? 0
616+
$result['hits']['hits'] ?? [],
617+
$result['hits']['total']['value'] ?? 0
618618
);
619619
}
620620

@@ -781,8 +781,6 @@ public function highlight($fragmentSize, ?int $fragmentCount = null, int $noMatc
781781
*/
782782
public function moreLikeThis(array $like, array $fields = [], array $options = []): ElasticSearchQueryBuilder
783783
{
784-
$like = is_array($like) ? $like : [$like];
785-
786784
$getDocumentDefinitionByNode = function (QueryInterface $request, NodeInterface $node): array {
787785
$request->queryFilter('term', ['neos_node_identifier' => $node->getIdentifier()]);
788786
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_search', [], $request->toArray())->getTreatedContent();
@@ -801,7 +799,7 @@ public function moreLikeThis(array $like, array $fields = [], array $options = [
801799

802800
$processedLike = [];
803801

804-
foreach ($like as $key => $likeElement) {
802+
foreach ($like as $likeElement) {
805803
if ($likeElement instanceof NodeInterface) {
806804
$documentDefinition = $getDocumentDefinitionByNode(clone $this->request, $likeElement);
807805
if (!empty($documentDefinition)) {
@@ -994,7 +992,7 @@ protected function getNearestFutureDate(string $dateField): int
994992
return (new \DateTime($dateResult['value_as_string']))->getTimestamp();
995993
};
996994

997-
$request->queryFilter('range', [$dateField => ['gt' => 'now']], 'must');
995+
$request->queryFilter('range', [$dateField => ['gt' => 'now']]);
998996
$request->aggregation('minTime', [
999997
'min' => [
1000998
'field' => $dateField

Classes/Eel/ElasticSearchQueryResult.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ public function getFirst()
168168
if (count($this->nodes) > 0) {
169169
return array_values($this->nodes)[0];
170170
}
171+
172+
return null;
171173
}
172174

173175
/**

Classes/Eel/SearchResultHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function didYouMean(ElasticSearchQueryResult $searchResult, float $scoreT
4646
foreach ($searchResult->getSuggestions()[$suggestionName] as $suggestion) {
4747
if (array_key_exists('options', $suggestion) && !empty($suggestion['options'])) {
4848
$bestSuggestion = current($suggestion['options']);
49-
$maxScore = $bestSuggestion['score'] > $maxScore ? $bestSuggestion['score'] : $maxScore;
49+
$maxScore = max($bestSuggestion['score'], $maxScore);
5050
$suggestionParts[] = $bestSuggestion['text'];
5151
} else {
5252
$suggestionParts[] = $suggestion['text'];

Classes/ErrorHandling/FileStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct()
3636
*/
3737
public function logErrorResult(array $errorResult): string
3838
{
39-
$referenceCode = date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5((string)rand()), 0, 6);
39+
$referenceCode = date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5((string)mt_rand()), 0, 6);
4040

4141
$filename = FLOW_PATH_DATA . 'Logs/Elasticsearch/' . $referenceCode . '.txt';
4242
$message = sprintf('Elasticsearch API Error detected - See also: Data/Logs/Elasticsearch/%s on host: %s', basename($filename), gethostname());

Classes/Indexer/NodeIndexer.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public function getIndex(): Index
216216
* Index this node, and add it to the current bulk request.
217217
*
218218
* @param NodeInterface $node
219-
* @param string|null $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
219+
* @param string|null $targetWorkspace In case indexing is triggered during publishing, a target workspace name will be passed in
220220
* @return void
221221
* @throws Exception
222222
*/
223-
public function indexNode(NodeInterface $node, $targetWorkspaceName = null): void
223+
public function indexNode(NodeInterface $node, $targetWorkspace = null): void
224224
{
225225
if ($this->nodeTypeIndexingConfiguration->isIndexable($node->getNodeType()) === false) {
226226
$this->logger->debug(sprintf('Node "%s" (%s) skipped, Node Type is not allowed in the index.', $node->getContextPath(), $node->getNodeType()), LogEnvironment::fromMethodName(__METHOD__));
@@ -247,7 +247,7 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null): voi
247247
$mappingType = $this->getIndex()->findType($nodeType->getName());
248248

249249
$fulltextIndexOfNode = [];
250-
$nodePropertiesToBeStoredInIndex = $this->extractPropertiesAndFulltext($node, $fulltextIndexOfNode, function ($propertyName) use ($documentIdentifier, $node) {
250+
$nodePropertiesToBeStoredInIndex = $this->extractPropertiesAndFulltext($node, $fulltextIndexOfNode, function ($propertyName) use ($node) {
251251
$this->logger->debug(sprintf('Property "%s" not indexed because no configuration found, node type %s.', $propertyName, $node->getNodeType()->getName()), LogEnvironment::fromMethodName(__METHOD__));
252252
});
253253

@@ -269,23 +269,21 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null): voi
269269
}
270270
};
271271

272-
$handleNode = function (NodeInterface $node, Context $context) use ($targetWorkspaceName, $indexer) {
272+
$handleNode = function (NodeInterface $node, Context $context) use ($targetWorkspace, $indexer) {
273273
$nodeFromContext = $context->getNodeByIdentifier($node->getIdentifier());
274274
if ($nodeFromContext instanceof NodeInterface) {
275-
$this->searchClient->withDimensions(static function () use ($indexer, $nodeFromContext, $targetWorkspaceName) {
276-
$indexer($nodeFromContext, $targetWorkspaceName);
275+
$this->searchClient->withDimensions(static function () use ($indexer, $nodeFromContext, $targetWorkspace) {
276+
$indexer($nodeFromContext, $targetWorkspace);
277277
}, $nodeFromContext->getContext()->getTargetDimensions());
278+
} elseif ($node->isRemoved()) {
279+
$this->removeNode($node, $context->getWorkspaceName());
280+
$this->logger->debug(sprintf('Removed node with identifier %s, no longer in workspace %s', $node->getIdentifier(), $context->getWorkspaceName()), LogEnvironment::fromMethodName(__METHOD__));
278281
} else {
279-
if ($node->isRemoved()) {
280-
$this->removeNode($node, $context->getWorkspaceName());
281-
$this->logger->debug(sprintf('Removed node with identifier %s, no longer in workspace %s', $node->getIdentifier(), $context->getWorkspaceName()), LogEnvironment::fromMethodName(__METHOD__));
282-
} else {
283-
$this->logger->debug(sprintf('Could not index node with identifier %s, not found in workspace %s with dimensions %s', $node->getIdentifier(), $context->getWorkspaceName(), json_encode($context->getDimensions())), LogEnvironment::fromMethodName(__METHOD__));
284-
}
282+
$this->logger->debug(sprintf('Could not index node with identifier %s, not found in workspace %s with dimensions %s', $node->getIdentifier(), $context->getWorkspaceName(), json_encode($context->getDimensions())), LogEnvironment::fromMethodName(__METHOD__));
285283
}
286284
};
287285

288-
$workspaceName = $targetWorkspaceName ?: $node->getContext()->getWorkspaceName();
286+
$workspaceName = $targetWorkspace ?: $node->getContext()->getWorkspaceName();
289287
$dimensionCombinations = $this->dimensionService->getDimensionCombinationsForIndexing($node);
290288

291289
if (array_filter($dimensionCombinations) === []) {

Classes/Service/NodeTypeIndexingConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class NodeTypeIndexingConfiguration
4242
*/
4343
public function isIndexable(NodeType $nodeType): bool
4444
{
45-
if ($this->settings === null || !is_array($this->settings)) {
45+
if (!is_array($this->settings)) {
4646
return true;
4747
}
4848

0 commit comments

Comments
 (0)