Because you use the German collation, you need to add this filter function to keep the umlauts intact: https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_remove_punctuation/#remove_accents
Add that function and rebuild the index.
Thread Starter
morvy
(@morvy)
If I keep accents, search will find a word with accents but not without them. I believe I’m missing something, but I’m trying filters one after another that I find on gist and in the docs and I can’t get both versions working.
I also tried different collations, (german, unicode, both as utf8 and utf8mb4)
-
This reply was modified 4 years, 1 month ago by
morvy.
“If I keep accents, search will find a word with accents but not without them.”
This is correct, and how the search should work in that case.
If that is not what you want, you need to run remove_accents(). There’s one wrinkle here, though: in German locales, remove_accents() doesn’t remove the umlauts. Instead, ä becomes ae, ü becomes ue and so on. So “natürlich” would be indexed as “natuerlich” and thus can only be found when searching for “natürlich” or “natuerlich”, but not when you search for “naturlich”.
If you want the search to ignore accents and umlauts, use the utf8mb4_unicode_ci collation, let the remove_accents() run and add this:
add_filter( 'relevanssi_remove_punctuation', function( $string ) {
$chars = array(
'ü' => 'u',
'ä' => 'a',
'ö' => 'o',
'Ü' => 'U',
'Ä' => 'A',
'Ö' => 'O',
);
return strtr( $string, $chars );
}, 8 );
This would make Relevanssi index the umlauted characters without the umlauts and without the extra “e” remove_accents() adds.
Thread Starter
morvy
(@morvy)
Thanks a lot, this does the job!
I have the same problem. I don’t know where to write your codes. I’m inexperienced at this. I appreciate your help.
Thank you for giving such quick feedback.