Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ignoring special characters
- This topic has 7 replies, 2 voices, and was last updated 5 years, 11 months ago by
Ernest Marcinko.
-
AuthorPosts
-
June 25, 2020 at 10:38 am #28080
msamavi64
ParticipantHi Ernest,
Please let me describe a bit about my requirements as we talked earlier:
In my Woocommerce website I have products that have special characters in their titles, for example:
Dīvān-i ashʻār-i Jalāl Ṭabīb Shīrāzī / Naṣr Allāh Pūrjavādī
I would like the visitors to be able to find the above product using any of the following search phrases:
divani
ashari
tabib
nasr
purjavThe html character codes I sent to you in my previous message were related to the special characters you see on the top and bottom of some the normal characters of the above-mentioned title example (īʻāṬṣāūāī)
If you guarantee that you will solve this for me, I will buy your plugin immediately.
Kind regards,
MajidJune 25, 2020 at 1:11 pm #28087Ernest Marcinko
KeymasterHi Majid,
So, my suggestion is using a custom code with the index table engine. The custom code will try to replace these characters with the single unicode versions on both the server and client side.
Please follow the instructions below:
1. Please add this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
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', '', '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; }2. Make sure to configure the index table engine. Follow the tutorial.
3. Once ready and the indexing is finished. Make sure the index table is enabledIf all goes right, entering the words should yield results. The code will only replace the given characters, only the lowercase versions. For this to work with the upper case, it needs to be added as well.
-
This reply was modified 5 years, 11 months ago by
Ernest Marcinko. Reason: Fixed code
June 25, 2020 at 1:24 pm #28089msamavi64
ParticipantHi Ernest,
Thank you for the reply.
The search engine was already set to index table.
I created a snippet containing your code.
I deleted the index.
I clicked on “Create new index” button, but it indexed only one item. (problem!)
I disabled your code snippet.
I clicked on “Create new index” button, then all items were indexed successfully as before.It seems the code snippet prevents indexing.
Any comment please?Best,
MajidJune 25, 2020 at 1:26 pm #28090Ernest Marcinko
KeymasterHi Majid,
Indeed, there is an error in the code, please try this variation:
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', '', '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; }June 25, 2020 at 1:37 pm #28092msamavi64
ParticipantErnest,
It seems it works!
I have added two other special characters, those worked as well 🙂I’m very happy now!
Let me check further.Best,
MajidJune 25, 2020 at 1:38 pm #28093Ernest Marcinko
KeymasterThat is really great to hear 🙂 It may not work with everything, but should do most of them.
June 25, 2020 at 3:22 pm #28095msamavi64
ParticipantHi Ernest,
One issue regarding small and capital letters (case sensitivity):
If we use:
$original = array(
‘Ā’, ‘ā’
);
$replace = array(
‘A’, ‘a’
);Only search string “Ava” will find the post title “Āvā”. How to make it case insensitive so that it can also be found with search strings like: “ava” or “avA” ?
Regards,
MajidJune 26, 2020 at 7:26 am #28096Ernest Marcinko
KeymasterHi Majid,
Use the lower case for both in the replacement:
$original = array( 'Ā', 'ā' ); $replace = array( 'a', 'a' ); -
This reply was modified 5 years, 11 months ago by
-
AuthorPosts
- The topic ‘Ignoring special characters’ is closed to new replies.