• Resolved janhamer

    (@janhamer)


    our users often use other spellings for words with german umlauts, e.g. “ue” instead of “ü”. is there a hack so that such spellings are found in the search?

    we tried with adding search terms as “pinned keywords”. strangely enough, this does not work in such cases.
    e.g.: pinned keyword “moedlich” for “mödlich” (name of a place). “moedlich” is not found in the search, other “pinned keywords” work without any problems. what could be the reason ?

    • This topic was modified 1 year, 4 months ago by janhamer.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    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).

    Thread Starter janhamer

    (@janhamer)

    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.
    Plugin Author Mikko Saari

    (@msaari)

    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 );
    } );
    
    Thread Starter janhamer

    (@janhamer)

    Thanx

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘german umlauts and pinning’ is closed to new replies.