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.
Hi Mikko,
is there a similar way to handle with german plural words using Relevanssi Premium?
Thanks so much,
Ina
You can use this simple German stemmer: https://gist.github.com/msaari/fa322fd49b3f0f6a78c59d7fbc42da7b
Just add the code to your theme functions.php and rebuild the index.
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
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.
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.
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.
Sorry but we don’t have much coding experience.
If we purchase the premium version, will we be able to include that greek stemmer with relevanssi?
https://github.com/magaras/greek_stemmer
Thank you.
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.
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.
This function will strip vowels from the end of the word:
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,
Steve
Steve, set the “Keyword matching” setting in Relevanssi searching settings to “Partial matches”, and you should be fine.
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,
Mariah
Mariah, you can use the function on this page. In the free version, just use
relevanssi_remove_punctuation
instead ofrelevanssi_stemmer
.Hi Mikko,
It worked! Thank you so much 🙂
Sincerly,
Mariah
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.
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).
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.
Lee, add this to your theme functions.php to enable the stemmer:
add_filter( 'relevanssi_stemmer', 'relevanssi_simple_english_stemmer' );
Then rebuild the index.
Hey Mikko;
I would like to have this snippet code on “Simple PERSIAN plurals”.
In persian language we have “ها” and “ان” that makes the nouns plural.
Can you please modify this code for Persian language?
Something like this:
add_filter( 'relevanssi_stemmer', 'relevanssi_persian_plural_stemmer' );
function relevanssi_persian_plural_stemmer( $term ) {
$len = strlen( $term );
$end1 = substr( $term, -2, 2 );
if ( 'ها' === $end1 && $len > 3 ) {
$term = substr( $term, 0, -2 );
}
elseif ( 'ان' === $end1 && $len > 3 ) {
$term = substr( $term, 0, -2 );
}
return $term;
}
I’m assuming those characters are actually two characters; if they’re not, this won’t work and will need adjustment.
Yes both are two characters.
“ان” comes right after the word to make it plural.
but “ها” mostly comes after a space or minispace like: “noun + space + ها”
for example:
درختها
درخت ها
درختها
all three words above are all the same.
Is this case it needs any adjustment?
Thanks in advance.
Yes, it needs some adjustment. Now it’s just looking for the characters at the end of the word. If it’s separated with a space, then Relevanssi will just ignore it anyway, so that doesn’t matter. I’m not sure about the minispace, I don’t know what that is.
Mini Space is called “No-Width Optional Break” in word, and “ZWNJ” (zero-width non-joiner) in unicode characters,.
As it’s understandable from it’s name, it breaks the words without space between them like:
درختها is without space
درخت ها is with space
درختها is with mini space *
Plural noun = “Single noun + ZWNJ + ها”
As I think it’s 3 characters that makes the noun plural, 1 for “ZWNJ” character and 2 for “ها” at the end of the single noun
I assume ZWNJ is treated as a space, so it shouldn’t be a problem. Try it out and see what happens.