Search by latin characters in non-latin texts (transliteration)

Is it possible to search by latin characters and find its close non-latin words?
For example user enters: “suss” and it finds the word / text “Süss”

you could overwrite the built in search with a custom one. kirby does search for all keyword when split by a space so suss could be extended to suss süss to make the search behave the way you want it to also look for some diacrits.

My current code wont work if you have words like süssung because it would look for süssüng.

'components' => [
        'search' => function ($kirby, $collection, string $query = null, $params = []) {
            $query = implode(' ', array_map(function ($item) {
                foreach (['u' => 'ü', 'o' => 'ö', 'a' => 'ä'] as $orig => $diacrit) {
                    $item = $item . ' ' . str_replace($orig, $diacrit, $item);
                }
                return $item;
            }, explode(' ', strtolower($query))));

            return $kirby->nativeComponent('search')($kirby, $collection, $query, $params);
        }
    ],
1 Like

Thank You @bnomei, but as You already pointed out - then it would not work for other cases where one letter is in latin and other with umlaut.
So thinking of possibility to convert all site texts to latin, then do search with also converted to latin input (for example if user enters “suss” or “süss”, then search is done anyways via latin converted word “suss”). The problem is that result should be as its normally is in UTF-8 with all language specific characters…

Hmm, seems that other folks already discussed transliteration in search: How to do transliteration in search?

Setting locale did not help to do transliteration for search…