mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
Added name highlighting in search results
This commit is contained in:
parent
f30b937bb0
commit
ab4e99bb18
@ -30,11 +30,17 @@ class SearchResultsFormatter
|
|||||||
$textContent = $entity->$textProperty;
|
$textContent = $entity->$textProperty;
|
||||||
$terms = array_merge($options->exacts, $options->searches);
|
$terms = array_merge($options->exacts, $options->searches);
|
||||||
|
|
||||||
$matchRefs = $this->getMatchPositions($textContent, $terms);
|
$originalContentByNewAttribute = [
|
||||||
$mergedRefs = $this->sortAndMergeMatchPositions($matchRefs);
|
'preview_name' => $entity->name,
|
||||||
$content = $this->formatTextUsingMatchPositions($mergedRefs, $textContent);
|
'preview_content' => $textContent,
|
||||||
|
];
|
||||||
|
|
||||||
$entity->setAttribute('preview_content', new HtmlString($content));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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}}">
|
<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>
|
<span role="presentation" class="icon text-{{$type}}">@icon($type)</span>
|
||||||
<div class="content">
|
<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 ?? '' }}
|
{{ $slot ?? '' }}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
Loading…
Reference in New Issue
Block a user