mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Added name highlighting in search results
This commit is contained in:
@ -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);
|
||||
$originalContentByNewAttribute = [
|
||||
'preview_name' => $entity->name,
|
||||
'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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user