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

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