From: Dan Brown Date: Sat, 30 Sep 2017 13:14:23 +0000 (+0100) Subject: Updated search indexer to split words better X-Git-Tag: v0.18.2~1^2~8 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/5fd04fa470e5438d3afba43ac01f853cca977e5a?ds=inline Updated search indexer to split words better Will now split up words based on more chars than just spaces. Not takes into account newlines, tabs, periods & commas. Fixed #531 --- diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index bb92a1d7c..aebeace1e 100644 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -382,11 +382,13 @@ class SearchService protected function generateTermArrayFromText($text, $scoreAdjustment = 1) { $tokenMap = []; // {TextToken => OccurrenceCount} - $splitText = explode(' ', $text); - foreach ($splitText as $token) { - if ($token === '') continue; + $splitChars = " \n\t.,"; + $token = strtok($text, $splitChars); + + while ($token !== false) { if (!isset($tokenMap[$token])) $tokenMap[$token] = 0; $tokenMap[$token]++; + $token = strtok($splitChars); } $terms = [];