From df2dad8a68ba6cf1e8aa8531b5f93735f33a7e72 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 25 Oct 2019 13:39:26 +0200 Subject: [PATCH] add option to disable tag/category releated search If you set the tag multiplier to 0 it currently still searches posts with the same tags. Since this is called multiplier I'd expect it to ignore the tags if it is set to zero. --- Classes/Domain/Repository/PostRepository.php | 52 +++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Classes/Domain/Repository/PostRepository.php b/Classes/Domain/Repository/PostRepository.php index 2925dd6a..f336d96c 100644 --- a/Classes/Domain/Repository/PostRepository.php +++ b/Classes/Domain/Repository/PostRepository.php @@ -306,34 +306,38 @@ public function findRelatedPosts(int $categoryMultiplier = 1, int $tagMultiplier $currentPost = $this->findCurrentPost(); if ($currentPost instanceof Post) { - foreach ($currentPost->getCategories() as $category) { - $postsOfCategory = $this->findAllByCategory($category); - /** @var Post $postOfCategory */ - foreach ($postsOfCategory as $postOfCategory) { - if ($postOfCategory->getUid() === $currentPost->getUid()) { - continue; - } - - if (!array_key_exists($postOfCategory->getUid(), $selectedPosts)) { - $selectedPosts[$postOfCategory->getUid()] = $categoryMultiplier; - } else { - $selectedPosts[$postOfCategory->getUid()] += $categoryMultiplier; + if ($categoryMultiplier > 0) { + foreach ($currentPost->getCategories() as $category) { + $postsOfCategory = $this->findAllByCategory($category); + /** @var Post $postOfCategory */ + foreach ($postsOfCategory as $postOfCategory) { + if ($postOfCategory->getUid() === $currentPost->getUid()) { + continue; + } + + if (!array_key_exists($postOfCategory->getUid(), $selectedPosts)) { + $selectedPosts[$postOfCategory->getUid()] = $categoryMultiplier; + } else { + $selectedPosts[$postOfCategory->getUid()] += $categoryMultiplier; + } } } } - foreach ($currentPost->getTags() as $tag) { - $postsOfTag = $this->findAllByTag($tag); - /** @var Post $postOfTag */ - foreach ($postsOfTag as $postOfTag) { - if ($postOfTag->getUid() === $currentPost->getUid()) { - continue; - } - - if (!array_key_exists($postOfTag->getUid(), $selectedPosts)) { - $selectedPosts[$postOfTag->getUid()] = $tagMultiplier; - } else { - $selectedPosts[$postOfTag->getUid()] += $tagMultiplier; + if ($tagMultiplier > 0) { + foreach ($currentPost->getTags() as $tag) { + $postsOfTag = $this->findAllByTag($tag); + /** @var Post $postOfTag */ + foreach ($postsOfTag as $postOfTag) { + if ($postOfTag->getUid() === $currentPost->getUid()) { + continue; + } + + if (!array_key_exists($postOfTag->getUid(), $selectedPosts)) { + $selectedPosts[$postOfTag->getUid()] = $tagMultiplier; + } else { + $selectedPosts[$postOfTag->getUid()] += $tagMultiplier; + } } } }