-
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the Bug
Searching text with or without diacritics works great! 👍
Although the highlighted text works only if an exact match is found on getMatchPositions
| $pos = mb_strpos($text, $term, $offset); |
So search a text like δοκιμή will only get highlighted only if enter as written on a page. Entering text δοκιμη works, but no highlighted text shown on search results.
The following patch fixes the issue, using transliterator_transliterate to convert text to lower case without diacritics.
It requires package php-intl installed (eg apt-get install php8.2-intl).
diff --git a/app/Search/SearchResultsFormatter.php b/app/Search/SearchResultsFormatter.php index 9cbc5ee6..6bbab29a 100644 --- a/app/Search/SearchResultsFormatter.php +++ b/app/Search/SearchResultsFormatter.php @@ -84,11 +84,11 @@ class SearchResultsFormatter protected function getMatchPositions(string $text, array $terms): array { $matchRefs = []; - $text = mb_strtolower($text); + $text = transliterator_transliterate('NFD; [:Nonspacing Mark:] Remove; Lower; NFC;', $text); foreach ($terms as $term) { $offset = 0; - $term = mb_strtolower($term); + $term = transliterator_transliterate('NFD; [:Nonspacing Mark:] Remove; Lower; NFC;', $term); $pos = mb_strpos($text, $term, $offset); while ($pos !== false) { $end = $pos + mb_strlen($term); I believe above above change will work universally for all languages with diacritics.
Please consider accepting that change, if you believe it will improve BookStack.
Thanks!
Steps to Reproduce
- Create a page that contains text
δοκιμή(Greek word for test, with ή -> GREEK SMALL LETTER ETA WITH TONOS) - Got to 'search'
- Type word
δοκιμη(small letters without diacritics) - Search results appear but text
δοκιμήis not highlighted
Expected Behaviour
The text δοκιμή should be highlighted, since it was possible to search that text.
Screenshots or Additional Context
No response
Browser Details
No response
Exact BookStack Version
v23.02.3
PHP Version
8.2.5
Hosting Environment
Debian 11 with PHP 8.2 by @armando-femat