From ce5e8a6500760d5c4a5b0fa70e9aa2f4c11e6116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20B=C3=BClter?= Date: Fri, 23 Aug 2024 11:20:31 +0200 Subject: [PATCH] [BUGFIX] Fix cropping if "resultChars" is empty. closes #242 --- ChangeLog | 3 +++ Classes/Lib/Searchresult.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64cd69b01..3a857e238 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ ChangeLog +Upcoming version +[BUGFIX] Fix cropping if "resultChars" is empty. Thanks to Andreas Kießling. https://github.com/tpwd/ke_search/issues/242 + Version 5.5.1, 16 August 2024 [FEATURE] Add garbage collection for statistics table [BUGFIX] Use correct table names for query builder or connection. Thanks to Andreas Kießling. https://github.com/tpwd/ke_search/issues/228 diff --git a/Classes/Lib/Searchresult.php b/Classes/Lib/Searchresult.php index ba2637ab6..eb9398855 100644 --- a/Classes/Lib/Searchresult.php +++ b/Classes/Lib/Searchresult.php @@ -242,7 +242,7 @@ public function buildTeaserContent(string $content): string $amountOfSearchWords = count($this->swords); // with each new searchword and all the croppings here the teaser for each word will become too small/short // I decided to add 20 additional letters for each searchword. It looks much better and is more readable - $charsForEachSearchWord = ceil($this->conf['resultChars'] / $amountOfSearchWords) + 20; + $charsForEachSearchWord = ceil(($this->conf['resultChars'] ?? 0) / $amountOfSearchWords) + 20; $charsBeforeAfterSearchWord = ceil($charsForEachSearchWord / 2); $aSearchWordWasFound = false; $isSearchWordAtTheBeginning = false; @@ -299,7 +299,7 @@ public function buildTeaserContent(string $content): string // When the searchword was found in title but not in content the teaser is empty // in that case we have to get the first x letters without containing any searchword if ($aSearchWordWasFound === false) { - $teaser = $cObj->crop($content, $this->conf['resultChars'] . '||1'); + $teaser = $cObj->crop($content, ($this->conf['resultChars'] ?? 0) . '||1'); } elseif ($isSearchWordAtTheBeginning === true) { $teaser = implode(' ', $teaserArray); } else { @@ -312,6 +312,6 @@ public function buildTeaserContent(string $content): string } return $teaser; } - return $cObj->crop($content, $this->conf['resultChars'] ?? 0 . '|…|1'); + return $cObj->crop($content, ($this->conf['resultChars'] ?? 0) . '|…|1'); } }