Author Topic: Searching for similar characters like a, á; e, é; etc...  (Read 993 times)

Offline svsanchez

  • Posts: 449
Searching for similar characters like a, á; e, é; etc...
« on: June 13, 2018, 11:15:20 PM »
Hello, I found the file search_convert.php where I can define some characters like á, é, í, ó, ú and define them as similar to a, e, i, o, u so that if a user searches for "plástico" it will also show him entries without the accent, like "plastico".

However, after defining my similar characters, I get the following warnings on the search results page:

Resultados para 'plástico':
Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

This is what I added on my search_convert.php file:

// local Spanish settings
if($search_lang=='ES') { // Yo agregué esto
   $t["á"] = array("á", "a");
   $t["é"] = array("é", "e");
   $t["í"] = array("í", "i");
   $t["ó"] = array("ó", "o");
   $t["ú"] = array("ú", "u");
   $t["ñ"] = array("ñ", "n");      
   $t["a"] = array("a", "á");
   $t["e"] = array("e", "é");
   $t["i"] = array("i", "í");
   $t["o"] = array("o", "ó");
   $t["u"] = array("u", "ú");
}

Could someone please tell me how to solve those warnings?

Thank you!

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2976
  • Gender: Female
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #1 on: June 13, 2018, 11:43:38 PM »
why you dont make use of the php transliterator?
check it out and try it... ;)
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #2 on: June 15, 2018, 05:19:07 PM »
Hello DarkViper, thank you for your suggestion. I asked my host about Transliterator and this is what they replied:

Currently we have verified that your server has the PHP extension `php56-php-intl` installed. So you will be able to implement this function. However coding and content managment is outside our scope of support. We would recommend Having a Website Developer implement that function into your code.

What I understand is that I have to add some Transliterator code on search_convert.php in order to show the both the accented and non-accented characters in the search, but I have no idea how to do this. Could someone please tell me what I have to add and where to use Transliterator, or how to remove the "Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432" messages that I currently have on my site after adding the code for defining the accented characters?

Thank you!

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #3 on: June 19, 2018, 06:00:32 PM »
Hello again, could someone please tell me how to remove these errors from appearing when I perform searches on my site? The search engine is looking for accented and unaccented characters, BUT it's also showing these errors:

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #4 on: June 21, 2018, 05:29:05 AM »
Hello, I'm sorry to insist with this, but is there a solution to those warnings?

Currently I had to configure php.ini to not show any warnings but this is not a solution!

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #5 on: June 21, 2018, 07:30:58 AM »
Hello, do you mean the warnings are displayed in the frontend?

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #6 on: June 25, 2018, 06:35:33 AM »
Hello dbs, yes the warnings are displayed in the frontend, even with PHP Error Reporting Level: E-NONE

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #7 on: June 25, 2018, 08:02:57 AM »
I have added your codeblock to search_convert.php and created a test wysiwyg section. The search works, but this messages occours in the errorlog.
Code: [Select]
[E_NOTICE] /search/search_modext.php:[432] from /search/search.php:[411] wysiwyg_search "Undefined offset: 0"
[E_WARNING] /search/search_modext.php:[432] from /modules/wysiwyg/search.php:[26] search_make_sql_part "strtr(): The second argument is not an array"

Have also added a new file search_convert_loca l.php in folder search, pasted your codeblock. Works also, with the same messages.
You should also create this file to prevent overwriting the search_convert.php (and there your own code) by the next upgrade.

Offline evaki

  • Posts: 2220
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #8 on: June 25, 2018, 10:27:21 AM »
@dbs
Hab das gleiche nun auch mal vollzogen: Keinerlei Meldungen, auch nix in log. dev und debug an.
Zeichenkette á é í ó ú ñ a e i o u wird gefunden.

Hat ein BOM Auswirkungen auf die Ausführung? -ich frag ja nur mal wieder ganz ohne Vorüberlegungen, und ohne daß ich mir den Hintergrund oder Grundsätzliches dazu angelesen hätte  :-D

MfG. Evaki
Einmal Pizza Quattro Stagioni bitte, aber ohne Herbst.

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #9 on: June 25, 2018, 10:42:26 AM »
I'm not a programmer, but BOM is bäh  :-D
Don't think about, don't use it.

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2976
  • Gender: Female
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #10 on: June 27, 2018, 12:58:18 AM »
Ich hab mal einen kurzen Anriss des  'etwas' komplexen Themas zusammengeschrieben .
Rund um UTF-8
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

Offline evaki

  • Posts: 2220
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #11 on: June 27, 2018, 06:40:17 AM »
Quote
Im Anfang herrschte das Chaos
Jo, dann trat Moses mit  Genesis auf, und ging damit in die Geschichte ein, wie man in der Hall of Fame (Vatikanstadt) sehen kann. Was sagt uns das? Mit Musik geht alles besser, wußte man schon anno dunnemals.
MfG. Evaki
p.s. Zu mehr hats heute Morgen noch nicht gereicht  :-D
 
Einmal Pizza Quattro Stagioni bitte, aber ohne Herbst.

Offline crnogorac081

  • Posts: 1879
  • Gender: Male
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #12 on: June 27, 2018, 11:10:28 AM »
Sorry for english,

do you need this inside integrated wb search function or you are building your own ?

If you are building your own search function, I can send you code that will help you.
no bb in signature

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #13 on: July 02, 2018, 08:36:56 AM »
Sorry, I got lost with the comments in German.

@dbs: I created another search_convert_es file but it didn't work, so I ended up using the original one getting basically the same error you saw in your error log:

Warning: strtr(): The second argument is not an array in /home/distribu/public_html/search/search_modext.php on line 432

I don't understand why that error appears when I add the Spanish characters, but it works with the original German characters...

I had to disable all php warnings in order to not show the error in the frontend, but I would like to correct the above error...

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #14 on: July 02, 2018, 08:47:34 AM »
Hi, the file must have the name "search_convert_loca l.php".
You can see why in search_convert.php line 81.
Code: [Select]
<?php // include user-supplied file
if(file_exists(WB_PATH.'/search/search_convert_local.php'))
    include(
WB_PATH.'/search/search_convert_local.php');

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #15 on: July 02, 2018, 08:21:11 PM »
Hi dbs, ok I understand what you mean. However, when I rename the file search_convert_es.p hp to search_convert_loca l.php the search ceases to work at all. I guess it's finding the file and trying to use it, but then something crashes...

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #16 on: July 03, 2018, 07:43:13 AM »
Hi, the content of your file is this? ( inclusive <?php )
Code: [Select]
<?php

// local Spanish settings
if($search_lang=='ES') { // Yo agregué esto
   
$t["á"] = array("á" ,"a");
   
$t["é"] = array("é" ,"e");
   
$t["í"] = array("í" ,"i");
   
$t["ó"] = array("ó" ,"o");
   
$t["ú"] = array("ú" ,"u");
   
$t["ñ"] = array("ñ" ,"n");      
   
$t["a"] = array("a" ,"á");
   
$t["e"] = array("e" ,"é");
   
$t["i"] = array("i" ,"í");
   
$t["o"] = array("o" ,"ó");
   
$t["u"] = array("u" ,"ú");
}

Offline svsanchez

  • Posts: 449
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #17 on: July 03, 2018, 07:48:03 PM »
Hi dbs, the <?php is the first line of the file. In the search_convert.php file I have exactly what you wrote (replaced the local German settings with the Spanish ones). And in the search_convert_loca l file I have this after the local German settings:

// local Spanish settings
if($search_lang=='ES') { // Yo agregué esto
   $t["á"] = array("á", "a");
   $t["é"] = array("é", "e");
   $t["í"] = array("í", "i");
   $t["ó"] = array("ó", "o");
   $t["ú"] = array("ú", "u");
   $t["ñ"] = array("ñ", "n");      
}

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Searching for similar characters like a, á; e, é; etc...
« Reply #18 on: July 08, 2018, 06:39:33 PM »
Is the problem still present?
I would not dublicate the german settings. The local file will load addionally, so there is no german settings needed.
My try was only the code i posted.

The crash produced no messages in the errorlog?