From 5fd04fa470e5438d3afba43ac01f853cca977e5a Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 30 Sep 2017 14:14:23 +0100 Subject: [PATCH] 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 --- app/Services/SearchService.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 = [];