Skip to content

Commit

Permalink
[BUGFIX] Fix cropping if "resultChars" is empty. closes #242
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbltr committed Aug 23, 2024
1 parent 952340b commit ce5e8a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Classes/Lib/Searchresult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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');
}
}

0 comments on commit ce5e8a6

Please sign in to comment.