Posted on

Making ‘ß’ and ‘ss’ equivalent

When users search for words with specific German characters like “ß” they don’t get the results for words containing “ss” instead. This is important not only for those users who are not sure about the spelling but also those from countries like Switzerland who use German but don’t have this character on their keyboard (apparently). Is there a way to get Relevanssi to treat ‘ß’ like ‘ss’? It does work for umlauts…

Yes, and it’s easy, just add this code to theme functions.php and rebuild the index:

add_filter('relevanssi_remove_punctuation', 'ss_conversion', 9);
function ss_conversion($a) {
    $a = str_replace('ß', 'ss', $a);
    return $a;
}

Originally asked here.

6 comments Making ‘ß’ and ‘ss’ equivalent

  1. Hello,

    if I use the filter on german “ß” as described above, the highlighting in excerpt does not work anymore. Is there any way to get both to work: Getting results with “ss” and highlighting both word written with “ß” and “ss”?

    Thanks, Raul

        1. Yes, the search term gets transformed to “ss”, which doesn’t match the excerpt. Unfortunately there’s no simple solution that would make “ß” and “ss” equivalent while making the highlighting work.

  2. Hi Mikko,
    I have Arabic text. Some characters have multiple forms.
    I want to be able to offer search results for people who search using any of the character forms.

    I was using SearchWP but most likely will switch to the paid version of Relevanssi, as SearchWP has limitation in searching long paginated texts.

    relevanssi was able to search long paginated posts on my website.

    As for the problem i mentioned above, i had a function form the SearchWP team to do the job. how can this function be modified to suit Relevanssi?

    function my_searchwp_handle_conversions( $content ) {

    // find all words with أ, إ, آ, or ا and append variations of those words

    // to the content so people can search by any of the variations

    $characters = array( ‘أ’, ‘إ’, ‘آ’, ‘ا’, ‘ه’, ‘ة’, ‘ي’, ‘ى’ );

    $pattern = “/\b(\w*[” . implode( ”, $characters ) . “]\w*)\b/iu”;

    preg_match_all( $pattern, $content, $matches );

    if ( ! empty( $matches[0] ) ) {

    // loop through each match

    foreach ( $matches[0] as $match ) {

    // append each variation of this match to the content

    foreach ( $characters as $character ) {

    // if this match doesn’t have the current character variation…

    if ( false === strpos( $match, $character ) ) {

    // replace the character from this match with an alternate character

    // and append it to the content so it can be picked up by searches

    $content .= ‘ ‘ . str_replace( $characters, $character, $match );

    }

    }

    }

    }

    return $content;

    }

Leave a Reply

Your email address will not be published. Required fields are marked *