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

10 comments Simple French plurals

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

  2. 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;
      }

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.