Author Topic: Search for different variations of characters (a, á, à...)  (Read 441 times)

Offline svsanchez

  • Posts: 477
Hello everybody.

How can I tell the search module from Bakery to include different varations of a character when performing a search?

For example, when I search for the term "azucar", I would like that the search module returns results that include:

- Azucar
- Azúcar
- Azùcar
- Azûcar
- Azücar

Currently, it's only searching the word with the specific character that I use. So if the word is written correctly "azúcar" but users search for "azucar" without the accented ú, it shows no results.

Offline crnogorac081

  • Posts: 1895
  • Gender: Male
Re: Search for different variations of characters (a, á, à...)
« Reply #1 on: May 03, 2019, 02:41:46 AM »
If you know to code, i can send you custom code for this, i implemented it jn one of my projects..
no bb in signature

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #2 on: May 03, 2019, 08:33:00 AM »
Hello, I don't know PHP but if it's just a matter of adding your custom code to a file I can do that!

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #3 on: May 03, 2019, 01:47:07 PM »
If you know to code, i can send you custom code for this, i implemented it jn one of my projects..

I would be interested too
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #4 on: May 04, 2019, 02:12:00 AM »
Hello Crnogorac081, I just sent you in a private message the login details for a test site...

Offline crnogorac081

  • Posts: 1895
  • Gender: Male
Re: Search for different variations of characters (a, á, à...)
« Reply #5 on: May 04, 2019, 05:46:24 PM »
Here is code, test it on some hidden page.. main bakery items table must be utf-8

cheers
I.
no bb in signature

Offline crnogorac081

  • Posts: 1895
  • Gender: Male
Re: Search for different variations of characters (a, á, à...)
« Reply #6 on: May 04, 2019, 11:51:53 PM »
Someone test pls
no bb in signature

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #7 on: May 07, 2019, 08:31:29 AM »
Hello, I downloaded the bakery_search.zip file and unzipped it on my hard drive. I was expecting some code to add or change to one of the search files, but there 11 files so I'm confused:

- Do I have to upload all those 11 files?
- If yes, do they replace the files on /modules/bakery?
- Or do I have to upload he zip as a module?

Thank you!

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #8 on: May 07, 2019, 11:04:12 AM »
bakery search test is a "stand alone module" - install it as a new module

add in the top of your shop page a (globale) section with this module, as result, you get a special search field. this module works with bootstrap and use also font-awesome.
It is very important, that the databasetable "mod_bakery_items"  with the item informations is formated with utf8, other charsets will not work

i'm not a bootstrap-user ( i work with w3css), so i've to change anything, but i see and test it on the live page from crnogorac081 and it works brilliant  (Y)
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #9 on: May 27, 2019, 09:11:20 PM »
Hello all, I wasn't able to work on this previously but I'm back on it.

As suggested, I changed the mod_bakery_items table to utf8_unicode_ci and installed the bakery_search_test module on my site.

I created a test page with the module at: https://www.distribuidoraalcance.com/pages/test.php

The search field appears, but nothing happens when I try to search for anything. There's also no "Search" button.

Also, Crnogorac081's page shows the search results in a dropdown, but I need to show them in the "normal" search results page.

What else do I have to do to achieve this?

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #10 on: May 28, 2019, 10:18:02 AM »
i did not found the frontend_body.js inside of the template - that file place the search submit button. Add this line as last line before this line with </body> (nearly at the end of the code from index.php of the used template)

Code: [Select]
<script id="bodyjs" src="<?php echo TEMPLATE_DIR?>/js/body.js"></script>
from my view, it is also important, to include the bootstrap-Files directly in this CSS, but i'm not the bootstrap-expert
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #11 on: May 28, 2019, 11:11:07 AM »
forget the code in my last answer, this here is the correct code to include the frontend_body.js automatically - sorry for the trouble, maybe, a admin can remove the wrong code in the last posting - thx

Code: [Select]
<?php
// if you want to include jquery before body end,
#register_frontend_modfiles_body('jquery');
// automatically include optional WB module file frontend_body.js) should be always set
register_frontend_modfiles_body('js');
?>
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #12 on: May 28, 2019, 08:15:37 PM »
Hello Jacoby, thank you for your reply. I added the code to my template but it still doesn't work (no search button / no search is performed when I hit the ENTER key).

I had some similar lines on my <head> section, this is what I have now:

Code: [Select]
<?php
// automatically include optional WB module files (frontend.css, frontend.js)
if (function_exists('register_frontend_modfiles')) {
register_frontend_modfiles('css');
// register_frontend_modfiles('jquery');
register_frontend_modfiles('js');
?>


<?php
// if you want to include jquery before body end,
#register_frontend_modfiles_body('jquery');
// automatically include optional WB module file frontend_body.js) should be always set
register_frontend_modfiles_body('js');
?>



Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #13 on: May 29, 2019, 01:50:54 AM »
the code is correct, but deactivated

Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #14 on: May 29, 2019, 07:41:06 AM »
Hello Jacobi, there was that portion of code deactivated because it was twice on the page, the 'activated' code was a few lines above. I removed the duplicated code but it still doesn't work. I'm also curious to know how are you seeing that code, when I open the page in my browser and see the source code I get this:

Code: [Select]
<title>
Test - Distribuidora Alcance - </title>

<link rel="stylesheet" href="/modules/WBLingual/frontend.css" media="screen" />
<link rel="stylesheet" href="/modules/anynews/frontend.css" media="screen" />
<link rel="stylesheet" href="/modules/bakery_search/frontend.css" media="screen" />
<script>
/* inserted by register_frontend_modfiles */
var URL = 'https://www.distribuidoraalcance.com';
var WB_URL = 'https://www.distribuidoraalcance.com';
var THEME_URL = 'https://www.distribuidoraalcance.com/templates/DefaultTheme';
var TEMPLATE_DIR = 'https://www.distribuidoraalcance.com/templates/internas';
var TEMPLATE = 'internas';
var EDITOR = 'ckeditor';
var LANGUAGE = 'ES';
</script>
<script src="/include/jquery/domReady-min.js"></script>
<script src="/include/jquery/LoadOnFly-min.js"></script>


<script src="/modules/bakery_search/frontend_body.js"></script>

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #15 on: May 29, 2019, 10:09:42 AM »
bakery_search/frontend_body.js was loaded on "the wrong place". in the actual script it will be loaded before JQuery is loaded

read the answer again
Add this line as last line before this line with </body> (nearly at the end of the code from index.php of the used template)

Code: [Select]
<?php
// if you want to include jquery before body end,
#register_frontend_modfiles_body('jquery');
// automatically include optional WB module file frontend_body.js) should be always set
register_frontend_modfiles_body('js');
?>
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #16 on: May 29, 2019, 08:50:25 PM »
Hello Jacobi, thank you for that, I had missed the "last line before </body>" part. After moving the code to the correct place, the search seems to work, however it still shows the results in a dropdown manner instead of the standard search results page.

How do I change that?

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #17 on: May 31, 2019, 06:09:09 AM »
Hello, I am still trying to get WB to search for both accented and unaccented characters. I had already fixed this in WB 2.8.3, but it got broken after the upgrade to WB 2.12. The way it had been fixed was through a file named search_convert.php and search_convert_loca l.php

Crnogorac's plugin does the trick, however it shows the results on a dropdown and we need to show the results in the normal WB search results page so that they show all the information and can also be printed.

How do I tell the search function to show the search results in the normal WB search results page?


Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #18 on: May 31, 2019, 12:17:52 PM »
(google translation)
the normal case: in WB the complete search is handled by the files in the folder / search.
Each module included in the project, which has a search.php file, prepares the records for it, that is, all the records for that module, regardless of the search term.
An example from me: Foldergallery - Image Search. I use keywords there, a period from - to, a title, a description, the picture category.
The search.php from the FG searches now all images from the database, plus the category, description, keywords, period. - and build a list. This list is sent to search / index.php, which compares all of my listed data with the search term and then filters out the relevant records.
This means that the intervention you have in mind can only be made in the files in the / search folder. There are already in the file search_convert.php or search_convert_ul.p hp such conversions as those Crnogorac makes in its file ajax.php, but in the originial only for the ecaxt letters, not for different variations

In the module bakery_search Crnogorac goes a different way. It generates its own output of the search results there and does not send this data to the search module.

The simplest and most sensible solution from my point of view would be to extend the search_convert..php with the missing parameters. But if this is not done by the developer, the next upgrade will be lost again.

The question is: why does it have to be the WB search for you?
At the beginning I suggested to integrate the search field of Crnogorac or this module above your bakery-sections. Then you have your shop pages as a "background" and the search hits from BakerySearch via Ajax on top of it.
On the current test page, it looks a bit empty of course because nothing else is there
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #19 on: May 31, 2019, 04:24:36 PM »
from my point (and dont forget, i'm not a developer)

/search / search_convert_ul.p hp

there, you have an array $search_table_ul_umlauts with definitions like this

Quote
"\xc3\xb3" => "(\xc3\xb3|\xc3\x93)",

the red part in front of the line is utf8-literal for a special char, in this case for Ó

the second part are the possible matches in the search term

\xc3\xb3 = ó (lower letter)
\xc3\x93 = Ó (upper Letter)

the red pipe between the chars means = or

a better example
Quote
\xc3\x9f" => "(\xc3\x9f|SS|ss)

ß is a german special char and means ss
the example means (in simple words) search for a match with ß or ss or SS

Use this List to found your needed special chars (for example = à), read in this line the utf8-literal value (= \xc3\xa0)

search for this literal in search_convert_ul.p hp and remember the line ( in my version WB 2.12.2!) in line 42 with
Quote
"\xc3\xa0" => "(\xc3\xa0|\xc3\x80)",
two allowed chars - à in lower and upper form

now search in the list for your favorite different variation for this char, copy the literal and add it with a pipe to the definition in search_convert_ul.p hp
for example for à, á, â, ã, ä À, Á, Â, Ã, Ä
these is the definition of the upper and lower letter
Quote
"\xc3\xa0" => "(\xc3\xa0|\xc3\xa1|\xc3\xa2|\xc3\xa3|\xc3\xa4|\xc3\x80|\xc3\x81|\xc3\x82|\xc3\x83|\xc3\x84)",

you have to change also the definition of the upper letter and this for every wished variation of a letter

tip:
- make a copy of this file search_convert_ul.p hp, rename it as (for example) search_convert_ul_t est.php
- search on this page in the list your favorite letter
- remember the literal from this list and search it in your copied file
- copy this line and add it directly in the next line, deactivate the first definition with a double slash in the front of this line, so that you have the untouched original code
- now add the variations like my example, for the variation of a in 10 lines

to test it, change this filename in search.php, Line 244
Code: [Select]
require_once(WB_PATH.'/search/search_convert_ul.php');
for a first test, i think, it is enough, to work with only one single char and his variations

P.S.: search.php has the possibility to add a own file, called search_convert_loca l.php, i think, this is a place for own definitions, but i dont have a example for a file like this




Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline crnogorac081

  • Posts: 1895
  • Gender: Male
Re: Search for different variations of characters (a, á, à...)
« Reply #20 on: May 31, 2019, 06:06:58 PM »
I told him he doesnt need to output it as dropdiwn list, it can be appended inside content div.
Example:

[ Search here: ...   ]

[  Search results:
    { no results }
]

So instead  puting results in dropdown list, you can output content between { }

Or any other way you want..

I wouldnt do this if i found this function or how to make it in wb search function file..

Cheers
I.
no bb in signature

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #21 on: May 31, 2019, 08:38:39 PM »
Hello Jacobi and Crnogorac, thanks a lot to both of you for your help.

Crnogorac's search module is very modern, but the main reason I wanted to list the search results in the traditional WB search fashion is to be able to print the results. The module needed a few extra tweaks too, since it was only showing a few results, the prices were not in the correct currency and part of the results were appearing on a layer below my footer. I´m sure these things wouldn't have been too difficult to correct, but in reality all I was asking since the beginning was a fix to include in the search results words with different show spanish characters.

By editing the /search/search_convert_ul.php file it worked!

Here are the lines that I added in case someone else needs to search for Spanish characters in WB 2.12:

Code: [Select]

    //a,á,A,Á
    "\x41" => "(\x41|\x61|\xc3\xa0|\xc3\xa1|\xc3\x80|\xc3\x81)",
    "\x61" => "(\x41|\x61|\xc3\xa0|\xc3\xa1|\xc3\x80|\xc3\x81)",
    "\xc3\xa0" => "(\x41|\x61|\xc3\xa0|\xc3\xa1|\xc3\x80|\xc3\x81)",
    "\xc3\xa1" => "(\x41|\x61|\xc3\xa0|\xc3\xa1|\xc3\x80|\xc3\x81)",

    //e,é,E,É
    "\x45" => "(\x45\x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\x65" => "(\x45\x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\xc3\xa8" => "(\x45\x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\xc3\xa9" => "(\x45\x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",

    //i,í,I,Í
    "\x49" => "(\x49|\x69|\xc3\x8d|\xc3\xad)",
    "\x69" => "(\x49|\x69|\xc3\x8d|\xc3\xad)",
    "\xc3\x8d" => "(\x49|\x69|\xc3\x8d|\xc3\xad)",
    "\xc3\xad" => "(\x49|\x69|\xc3\x8d|\xc3\xad)",

    //o,ó,O,Ó
    "\x4f" => "(\x4f|\x6f|\xc3\x93|\xc3\xb3)",
    "\x6f" => "(\x4f|\x6f|\xc3\x93|\xc3\xb3)",
    "\xc3\x93" => "(\x4f|\x6f|\xc3\x93|\xc3\xb3)",
    "\xc3\xb3" => "(\x4f|\x6f|\xc3\x93|\xc3\xb3)",

    //u,ú,U,Ú
    "\x55" => "(\x55|\x75|\xc3\xba|\xc3\x9a)",
    "\x75" => "(\x55|\x75|\xc3\xba|\xc3\x9a)",
    "\xc3\xba" => "(\x55|\x75|\xc3\xba|\xc3\x9a)",
    "\xc3\x9a" => "(\x55|\x75|\xc3\xba|\xc3\x9a)",

    //ñ,Ñ
    "\xc3\xb1" => "(\xc3\xb1|\xc3\x91)",
    "\xc3\x91" => "(\xc3\xb1|\xc3\x91)",


Again, thanks to both for your help!!!

Offline svsanchez

  • Posts: 477
Re: Search for different variations of characters (a, á, à...)
« Reply #22 on: May 31, 2019, 09:22:11 PM »
There was an error in the e,é,E,É portion, I forgot to separate some expressions with the | character. Here is the corrected code:

Code: [Select]
    //e,é,E,É
    "\x45" => "(\x45|x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\x65" => "(\x45|x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\xc3\xa8" => "(\x45|x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",
    "\xc3\xa9" => "(\x45|x65|\xc3\xa8|\xc3\xa9|\xc3\x88|\xc3\x89)",

Offline crnogorac081

  • Posts: 1895
  • Gender: Male
Re: Search for different variations of characters (a, á, à...)
« Reply #23 on: May 31, 2019, 10:58:31 PM »
Rename file from .php to .zip and upload it here.

Maybe someone else will need it.

no bb in signature

Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Search for different variations of characters (a, á, à...)
« Reply #24 on: June 01, 2019, 12:26:13 AM »
@ svsanchez: good job!  (Y)



Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.