Posted on

Simple French plurals

If you have Relevanssi Premium and want to make Relevanssi understand French plurals, you can add this code to your theme functions.php:

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);
    }
    else if ("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.

Leave a Reply

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