Yes. Depending on your database setup, you need one of these:
add_filter( 'relevanssi_remove_punctuation', function( $string ) {
$chars = array(
'ü' => 'u',
'ä' => 'a',
'ö' => 'o',
'Ü' => 'U',
'Ä' => 'A',
'Ö' => 'O',
);
return strtr( $string, $chars );
}, 8 );
or
// From a theme:
remove_filter( 'relevanssi_remove_punctuation', 'remove_accents', 9 );
// From a plugin:
add_action( 'init', function() {
remove_filter( 'relevanssi_remove_punctuation', 'remove_accents', 9 );
} );
You need the first one if your database ignores accents (i.e. searching for “mädchen” and “madchen” get the same results from the database) and the second one, if your database cares about accents (“mädchen” and “madchen” get different results).
that’s working fine, we are looking for a solution to find a result searching for “maedchen” as well. any idea ?
-
This reply was modified 1 year, 4 months ago by janhamer.
Here’s one method. This hooks into the indexing process and indexes words with ä, ö and ü both ways, so “mädchen” will be indexed both as “mädchen” and “maedchen”. Add this to theme functions.php and reindex:
add_filter( 'relevanssi_indexing_tokens', function( $tokens ) {
$new_tokens = array();
foreach ( $tokens as $token => $tf ) {
if ( strpos( $token, 'ä' ) !== false ) {
$new_tokens[ str_replace( 'ä', 'ae', $token ) ] = $tf;
}
if ( strpos( $token, 'ö' ) !== false ) {
$new_tokens[ str_replace( 'ö', 'oe', $token ) ] = $tf;
}
if ( strpos( $token, 'ü' ) !== false ) {
$new_tokens[ str_replace( 'ü', 'ue', $token ) ] = $tf;
}
}
return array_merge( $tokens, $new_tokens );
} );