Skip to content

Commit 09496ed

Browse files
committed
BUGFIX: No exception when document not found in MLT
In case only the live workspace is indexed to elastic and a new document is only available in a personal workspace, an exceptoion was thrown. Now the error is logged and ignored
1 parent 20ef50f commit 09496ed

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,12 @@ public function moreLikeThis($like, array $fields = [], array $options = [])
715715
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_search', [], $request->toArray())->getTreatedContent();
716716

717717
$respondedDocuments = Arrays::getValueByPath($response, 'hits.hits');
718+
718719
if (count($respondedDocuments) === 0) {
719-
throw new Exception(sprintf('The node with identifier %s was not found in the elasticsearch index', $node->getIdentifier()), 1536485615);
720+
$this->logger->log(sprintf('The node with identifier %s was not found in the elasticsearch index.', $node->getIdentifier()), LOG_INFO);
721+
return [];
720722
}
723+
721724
$respondedDocument = current($respondedDocuments);
722725
return [
723726
'_id' => $respondedDocument['_id'],
@@ -726,18 +729,28 @@ public function moreLikeThis($like, array $fields = [], array $options = [])
726729
];
727730
};
728731

732+
$processedLike = [];
733+
729734
foreach ($like as $key => $likeElement) {
730735
if ($likeElement instanceof NodeInterface) {
731-
$like[$key] = $getDocumentDefinitionByNode(clone $this->request, $likeElement);
736+
$documentDefinition = $getDocumentDefinitionByNode(clone $this->request, $likeElement);
737+
if (!empty($documentDefinition)) {
738+
$processedLike[] = $documentDefinition;
739+
}
740+
} else {
741+
$processedLike[] = $likeElement;
732742
}
733743
}
734744

735-
$this->request->moreLikeThis($like, $fields, $options);
745+
$processedLike = array_filter($processedLike);
746+
747+
if (!empty($processedLike)) {
748+
$this->request->moreLikeThis($processedLike, $fields, $options);
749+
}
736750

737751
return $this;
738752
}
739753

740-
741754
/**
742755
* Sets the starting point for this query. Search result should only contain nodes that
743756
* match the context of the given node and have it as parent node in their rootline.

0 commit comments

Comments
 (0)