plural words search doens’t seem to be working in my language.
-
Hi,
my site is in italian, and the plural words search doens’t seem to be working. For example, if I type “Agende” instead of “Agenda” i doesn’t find all products named “Agenda”, if Type “Penne” instead of “Penna” it finds just a copule products taht have “Penna” in the title but all products named “Penna”.
The page I need help with: [log in to see the link]
-
Hi,
When trying to access your site I see an error message. Can you please check it? I want to access the site and check the search form by myself.
Regards
Hi,
sorry about that, the site is now up again, you can check it, thank you.
Thanks, now it is working.
Looks like I found the solution for you. Please use following code snippet
add_filter( 'aws_search_terms', 'my_aws_search_terms' );
function my_aws_search_terms( $terms ) {
$new_terms = array();
foreach ( $terms as $term ) {
$new_terms[] = aws_italian_singulars($term);
}
return $new_terms;
}
add_filter( 'aws_extracted_terms', 'my_aws_extracted_terms' );
function my_aws_extracted_terms( $terms ) {
$new_terms = array();
foreach( $terms as $str_item_term => $str_item_num ) {
$str_item_term_new = aws_italian_singulars($str_item_term);
$new_terms[$str_item_term_new] = $str_item_num;
}
return $new_terms;
}
function aws_italian_singulars( $term ) {
$patterns = array(
'/i$/i' => 'o',
'/e$/i' => 'a',
'/chi$/i' => 'co',
'/ghi$/i' => 'go',
'/ci$/i' => 'ca',
'/gi$/i' => 'ga',
'/ie$/i' => 'io',
'/uomini$/i' => 'uomo',
'/dei$/i' => 'dio'
);
foreach ($patterns as $pattern => $replacement) {
if (preg_match($pattern, $term)) {
return preg_replace($pattern, $replacement, $term);
}
}
return $term;
}You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.
Also, after adding this code, you need to re-index the plugin table.
Hi,
yes it seems to be working now, thank you very much for the help!
Hi,
we noticed some words still not work using the plural:
CALENDARIO/CALENDARI
MARSUPIO/MARSUPI
PANTALONE/PANTALONI
BRACCIALE/BRACCIALI
BORRACCIA/BORRACCE
GIACCA/GIACCHE
IMPERMEABILE/IMPERMEABILI
OROLOGIO/OROLOGI
I tried implementing the code with more but it seems to be only working with orologi:function aws_italian_singulars( $term ) {
$patterns = array(
'/i$/i' => 'o', // Pantaloni -> Pantalone
'/i$/i' => 'io', // Calendarii -> Calendario
'/e$/i' => 'a', // Bracciali -> Bracciale
'/che$/i' => 'ca', // Giacche -> Giacca
'/ce$/i' => 'cia', // Borracce -> Borraccia
'/ci$/i' => 'cio', // Pasticci -> Pasticcio
'/gi$/i' => 'gio', // Orologi -> Orologio
'/ni$/i' => 'ne', // Pantaloni -> Pantalone
'/li$/i' => 'le', // Bracciale -> Bracciali
'/uomini$/i' => 'uomo', // Uomini -> Uomo
'/dei$/i' => 'dio', // Dei -> Dio
'/abili$/i' => 'abile', // Impermeabili -> Impermeabile
'/ie$/i' => 'io' // Specifica parole con suffisso -ie (pluralizzazione specifica)
);
foreach ($patterns as $pattern => $replacement) {
if (preg_match($pattern, $term)) {
return preg_replace($pattern, $replacement, $term);
}
}
return $term;
}Do you think you could help me with this?
Kind regards,
Nick-
This reply was modified 1 year, 5 months ago by
nickpn.
Hi,
So in your examples the first is singular and the second is plural form. Is that correct?Hi,
yes first one is singular, second one after the / is plural.
Can you give me an example of a search query that you currently have a problem with? Like you type it and expect to see product X but don’t see it.
Hi,
sure, if fore example you type in the search “giacca”, the search shows a list of all the products named “giacca” correctly. But if you type “giacche” the search shows no results or not the same results.
Ok, thanks for the explanation. Looks like it is indeed necessary to add some changes in the rules for plural/singular forms of words.
For now you can use the following code snippet:
add_filter( 'aws_plurals_singular_rules', 'my_aws_plurals_singular_rules', 10, 2 );
function my_aws_plurals_singular_rules( $rules, $lang ) {
if ( $lang === 'it' ) {
$rules = array(
'/che$/i' => 'ca',
'/ce$/i' => 'cia',
'/ci$/i' => 'cio',
'/gi$/i' => 'gio',
'/ni$/i' => 'ne',
'/abili$/i' => 'abile',
'/li$/i' => 'le',
'/uomini$/i' => 'uomo',
'/dei$/i' => 'dio',
'/ie$/i' => 'io',
'/i$/i' => 'o',
'/i$/i' => 'io',
'/e$/i' => 'a',
);
}
return $rules;
}Please reindex the plugin table after adding this code. I will also include those changes to the next plugin version.
ok, thank you.
-
This reply was modified 1 year, 5 months ago by
The topic ‘plural words search doens’t seem to be working in my language.’ is closed to new replies.