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

19 comments Simple French plurals

  1. Hi Mikko,
    is there a similar way to handle with german plural words using Relevanssi Premium?
    Thanks so much,

  2. Hello.

    We want to purchase premium version of relavanssi.

    But we want to know first.

    Does it support Greek stemmer?

    If no, will it?

    Does it support for example

    We have a product mobile and the user search for mobale. Will the plug in find the mobile product? Will it work on greek language too?

    Thank you

    1. Michael, Relevanssi doesn’t come with a Greek stemmer, but nothing prevents you from adding one. The “Did you mean” feature is language independent, it’s based on the actual words in your database and will thus work in any language. It would suggest “mobile”, if someone searches for “mobale” and that doesn’t find anything.

      1. Is there a documentation on how to add the stemmer? Do we have to know coding? We have a clothe store and want to know. For example. We have a product trouser with attribute color: black. The trouser and black are in greek language though. If someone search trouser black (in greek) the results for this product shows up with the free version of relavanssi. If the user now search trouser blacks (the plural of black in greek) the results doesn’t show the product. Will the premium version fix this problem?

        Thank you.

        1. Yeah, you need to understand PHP and Greek linguistics.

          Relevanssi, free or Premium, doesn’t actually understand language at all. You need some kind of stemmer to make plural and singular the same for Relevanssi.

          Greek is, well, all Greek to me, and I don’t know how the plurals work in Greek.If it’s something simple like the French plurals where you just remove “s” or “x” from the end, it’s really simple, but if it’s something like Finnish plurals, then it’s really quite complicated.

          1. Michael, it’s possible to add that Greek stemmer to Relevanssi, but it’s such a heavy, complicated stemmer that I can give absolutely no guarantees that it works. Relevanssi indexing or searching may become too slow.

            You may want to look at some of the more robust, high-performance search systems, like Lucidworks Site Search. They are probably better suited for your needs.

  3. Last question.

    Can i use the above code to strip the last specific characters from a search by making multiple else if?

    So for example if someone search the attribute of a product with its name


    Relevanssi will do a search for


    We want to remove the last greek vowels

    α, ε, η, ι, ο, υ, ω

    Thank you.

    1. This function will strip vowels from the end of the word:

      add_filter( 'relevanssi_stemmer', 'relevanssi_remove_greek_vowels' );
      function relevanssi_remove_greek_vowels( $term ) {
          $end1 = substr( $term, -1, 1 );
          if ( in_array( $end1, array( 'α', 'ε', 'η', 'ι', 'ο', 'υ', 'ω' ) ) {
              $term = substr( $term, 0, -1 );
          return $term;
  4. Hello Mikko,

    If the search is for the word fork and I have the word forks in several of my posts, there is no result returned for the posts with the word forks in it. Is there any way to have the search return the posts with the plural words in them after the singular?

    Thanks for your reply,

  5. Hi Mikko,

    The plural cannot find the singular forms in the free plugin. When we search for “kettles” the word kettle is not showing. How can we fixed this, please?

    Thank you,

  6. What about English plurals?

    If I search for ‘shop’ and again for ‘shops’ I get different results.

    Searching for the singular is fine and it finds the plurals, but not vice-versa.

    1. Lee, Relevanssi Premium includes an English stemmer, so doing something like this isn’t necessary. If you have free version, you can do something like this to handle English plurals (at least the regular ones).

      1. Thanks. Pretty sure this site that I’m working on has your Premium package.

        Maybe there is a switch that I have wrong. I have it set to partial words.

        1. Lee, add this to your theme functions.php to enable the stemmer:

          add_filter( 'relevanssi_stemmer', 'relevanssi_simple_english_stemmer' );

          Then rebuild the index.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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