Skip to main contentSkip to footer

If you have Relevanssi Premium and want to make Relevanssi understand French plurals, you can add this code to your site:

add_filter( 'relevanssi_stemmer', 'relevanssi_french_plural_stemmer' );
function relevanssi_french_plural_stemmer( $term ) {
    $len  = strlen( $term );
    $end1 = substr( $term, -1, 1 );
    if ( 's' === $end1 && $len > 3 ) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( 'x' === $end1 && $len > 3 ) {
        $term = substr( $term, 0, -1 );
    }
    return $term;
}

Then just rebuild the index, and now searching for plurals will also find the singular form. This is a very simple way to handle the plurals: it will simply strip the final “s” or “x” from a word.

It’s much better to use a proper stemmer, though.