Turkish characters not found

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Turkish characters not found

This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #31359
    memcan71
    memcan71
    Participant

    Hello,
    Our website is Turkish and English. In English side, there is no problem. But in Turkish side, I have problems with characters.

    For example, one of the doctor’s name is Elif Sarı . If I search like this “SARI” I find the doctor. But if I type “sarı” or “Sarı” it does not find the doctor.

    I have already changed to utf8mb4_unicode_520_ci but still no success. I would appreciate if you help.

    #31360
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    May I ask which plugin are you using for translations? Currently WPML and Polylang are fully supported only. Other plugins may not store the translation as a separate post type/user object, or might be within a custom field somewhere. I don’t think this is an issue with the database collation, that seems to be okay.
    It looks like the actualy member name is stored as “SARI”, and the translation is fetched during when the user name is requested depending on the language. If the plugin you are using uses custom fields to store the translated data, it might be possible to search those, if the custom field names are known. Otherwise it may not be possible.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #31362
    memcan71
    memcan71
    Participant

    I am using TranslatePress plugin for translation. I have changed the name to Sarı from SARI but still it finds when I enter in capıtal letters but does not find the “Sarı”.

    #31364
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    To add, even with those database collations, the turkish character “ı” is not going to match “i” or the capital version of it “I”. “ı” =/= “i”
    The database will treat those as completely different characters, I don’t think there is a collation which can cross match those characters. I tried testing different collations, but it seems like that is not possible.

    If “Sarı” didn’t match, that means the user details are still stored as “sari” or “SARI”, only the translation is changed. But again, I don’t know how that translation plugin works.

    I think you have maybe two ways of resolving this:

    1. To add a user meta field, witch the original/translated names and any other keywords and add that field to the search as well.
    2. Or use a character removal replacment code based on this tutorial. There was a similar issue with a different character set, which we resolved by using a custom code to replace characters in the search query string:

    add_filter('asp_indexing_string_pre_process', 'custom_chars_asp_indexing_string_pre_process', 10, 1);
    add_filter('asp_search_phrase_before_cleaning', 'custom_chars_asp_indexing_string_pre_process', 10, 1);
    add_filter('asp_query_args', 'custom_chars_asp_indexing_string_pre_process', 10, 1);
    function custom_chars_asp_indexing_string_pre_process($s) {
    	$original = array(
    		'ı', 'ī', 'ʻ', 'ā', 'Ṭ', 'ṣ', 'ū'
    	);
    	$replace = array(
    		'i', 'i', '', 'a', 't', 's', 'u'
    	);
    	
    	// Replace them
    	if ( is_array($s) ) {
    		if ( isset($s['s']) && !$s['_ajax_search'] ) 
    			$s['s'] = str_replace($original, $replace, $s['s']);      
    	} else {
    		$s = str_replace($original, $replace, $s);
    	}
    	
    	return $s;
    }

    But of course, this only works if the language of the stored names is always the same.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #31365
    memcan71
    memcan71
    Participant

    Will I experience the same problem if I use WPML? If that fix the problem, I can purchase it.

    #31366
    memcan71
    memcan71
    Participant

    I applied the snipped you have provided and it worked. Thanks a lot. How can I extend the list to include several other characters in different languages, let us say the ones in the German language?

    #31373
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Well, you can add more original characters to the $original variable on line 6. And the replacement characters to $replace on line 9.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.