]> BookStack Code Mirror - bookstack/commitdiff
Added name highlighting in search results
authorDan Brown <redacted>
Sat, 13 Nov 2021 12:44:27 +0000 (12:44 +0000)
committerDan Brown <redacted>
Sat, 13 Nov 2021 12:44:27 +0000 (12:44 +0000)
app/Entities/Tools/SearchResultsFormatter.php
resources/views/entities/list-item-basic.blade.php

index aaa5c129da1c0820eddf08b8d08307b3a742d755..24dc820a4e7b5865cf80a0bd7495d8a7b87a9a38 100644 (file)
@@ -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));
+        }
     }
 
     /**
index 2ec4bee5cc07dbf13db6b0978effd5990551cdc4..398c33b93f6c301fc09e0fff3b8a3a2470cae3fe 100644 (file)
@@ -2,7 +2,7 @@
 <a href="{{ $entity->getUrl() }}" class="{{$type}} {{$type === 'page' && $entity->draft ? 'draft' : ''}} {{$classes ?? ''}} entity-list-item" data-entity-type="{{$type}}" data-entity-id="{{$entity->id}}">
     <span role="presentation" class="icon text-{{$type}}">@icon($type)</span>
     <div class="content">
-            <h4 class="entity-list-item-name break-text">{{ $entity->name }}</h4>
+            <h4 class="entity-list-item-name break-text">{{ $entity->preview_name ?? $entity->name }}</h4>
             {{ $slot ?? '' }}
     </div>
 </a>
\ No newline at end of file