From: Dan Brown Date: Sat, 13 Nov 2021 12:44:27 +0000 (+0000) Subject: Added name highlighting in search results X-Git-Tag: v21.11~1^2~17^2~7 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/ab4e99bb187fb4273dcad2fa3c731ba46e49a585 Added name highlighting in search results --- diff --git a/app/Entities/Tools/SearchResultsFormatter.php b/app/Entities/Tools/SearchResultsFormatter.php index aaa5c129d..24dc820a4 100644 --- a/app/Entities/Tools/SearchResultsFormatter.php +++ b/app/Entities/Tools/SearchResultsFormatter.php @@ -30,11 +30,17 @@ class SearchResultsFormatter $textContent = $entity->$textProperty; $terms = array_merge($options->exacts, $options->searches); - $matchRefs = $this->getMatchPositions($textContent, $terms); - $mergedRefs = $this->sortAndMergeMatchPositions($matchRefs); - $content = $this->formatTextUsingMatchPositions($mergedRefs, $textContent); - - $entity->setAttribute('preview_content', new HtmlString($content)); + $originalContentByNewAttribute = [ + 'preview_name' => $entity->name, + 'preview_content' => $textContent, + ]; + + foreach ($originalContentByNewAttribute as $attributeName => $content) { + $matchRefs = $this->getMatchPositions($content, $terms); + $mergedRefs = $this->sortAndMergeMatchPositions($matchRefs); + $formatted = $this->formatTextUsingMatchPositions($mergedRefs, $content); + $entity->setAttribute($attributeName, new HtmlString($formatted)); + } } /** diff --git a/resources/views/entities/list-item-basic.blade.php b/resources/views/entities/list-item-basic.blade.php index 2ec4bee5c..398c33b93 100644 --- a/resources/views/entities/list-item-basic.blade.php +++ b/resources/views/entities/list-item-basic.blade.php @@ -2,7 +2,7 @@ @icon($type)
-

{{ $entity->name }}

+

{{ $entity->preview_name ?? $entity->name }}

{{ $slot ?? '' }}
\ No newline at end of file