mantobani Posted March 24, 2014 Share Posted March 24, 2014 Hi friends, First thanks to all fot the help you gave me. Im not a programmer, only kind of advanced user. I have a shop who some of the products have references like "s-01" or "T-01" this is with a "minus" character in the middle. This searches works well on back office, but in fron office it appears the code erases the minus and the first character "s" or "t", giving the search of the numbers only. I tried to manage the search options, keywords weight, word lenght, re-build index. (no result) I tried to edit classes/search.php to change some code that i think can delete the miinus character, but no results. Tried to edit aliases, and rebuid (nothing happens) I think is possible to add the backoffice search to the front. (I find an older threat with something from presta 1.4 but the code is significally different) In the code, the prestashop team let a note who says /* Copied from Drupal search module, except for \x{0}-\x{2f} that has been replaced by \x{0}-\x{2c}\x{2e}-\x{2f} in order to keep the char '-' */ I've searched in drupal and prestashop forums, i tried to put some unicode chars in the exceptions list. (no result) Can someone add some light to this? Sorry for my bad english. ---- Config: Linux #1 SMP Wed Feb 12 16:04:42 MSK 2014 x86_64 Apache PHP: 5.3.3 512M MySQL: 5.1.67 InnoDB PrestaShop: 1.5.6.2 Link to comment Share on other sites More sharing options...
IgorSB Posted April 13, 2014 Share Posted April 13, 2014 Hi, did you found solution for your problem? I have samoe problem, I need to to search with minus sign, for me in Prestashop 1.5.3.1 it i same result for example: "fx-10" and "fx 10", or "fx-------10", like there is no minus in search word. Please if you have solution, or somebody, help! Best regards, Igor Link to comment Share on other sites More sharing options...
PascalVG Posted April 13, 2014 Share Posted April 13, 2014 Hi, I'm no expert on preg_replace, but I think this does it. (Not fully sure if I 'allow' too much now, though. See below) In file: Classes/Search.php (make backup, and best to make an override class and override sanitize function (see dev guide on how to) public static function sanitize($string, $id_lang, $indexation = false, $iso_code = false) { $string = trim($string); if (empty($string)) return ''; $string = Tools::strtolower(strip_tags($string)); $string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8'); $string = preg_replace('/(['.PREG_CLASS_NUMBERS.']+)['.PREG_CLASS_PUNCTUATION.']+(?=['.PREG_CLASS_NUMBERS.'])/u', '\1', $string); $string = preg_replace('/['.PREG_CLASS_SEARCH_EXCLUDE.']+/u', ' ', $string); if ($indexation) // $string = preg_replace('/[._-]+/', ' ', $string); $string = preg_replace('/[._]+/', ' ', $string); else { $string = preg_replace('/[._]+/', '', $string); // $string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string)); $string = preg_replace('/[._]+/', '', $string); // $string = preg_replace('/[^\s]-+/', '', $string); } $blacklist = Tools::strtolower(Configuration::get('PS_SEARCH_BLACKLIST', $id_lang)); As you can see, I commented-out three lines (with // ), (and I added one line, see below) The first commented-out line: // $string = preg_replace('/[._-]+/', ' ', $string); I replaced (one line below it) with: $string = preg_replace('/[._]+/', ' ', $string); As you can see, I only took out the minus sign here (red indicated in original line). This makes that the minus sign will not be replaced with a space (so not creating two separate sub words), during reindexation. The other commented-out lines are used when searching, not indexing. These two lines, as far as I can see, searches for some (sub)string with a - (minus sign), and replaced with the (sub) string only. So I just took out these replacements to keep the minus signs intact. (N.B. Not 100% sure I 'allow' too much because of this. Any preg_replace expert any comment??) See sample here: In a demo shop, I added a string to the short description of the "iPod nano" product: (go to product detail for full short description text): oopad-nonno http://ps1562.buymethai.com/en/ (N.B. link to temp testshop, may not work in future) N.B. The general restriction in search isn't changed: you can only find words that START with the given string (like 'touc' (for touch) is found, but 'ouch' not, as the search string must start with the begin letter (t) to be found) That said, Try to play with it here in the sample shop. It seems that searching for: oop oopa oopad oopad- oopad-n oopad-no oopad-non oopad-nonn oopad-nonno and oopad iPod (two words, "start with", both exist in same product) all works not works: oopadn (no - sign, so not found) oopadnonno (no - sign, so not found) nonno (nonno isn't added separately, as the only word added to the index is oopad-nonno) -nonno (the word starts with oopad, -nonno isn't indexed separately) etc. as the - sign is really part of the word, (and the word starts with oopad). (In database, there's only one index word "oopad-nonno", no variations, partial strings) Hope this does the trick, pascal. 4 Link to comment Share on other sites More sharing options...
IgorSB Posted April 28, 2014 Share Posted April 28, 2014 PascalVG, you are the man, thank you very much!!!! I was cheching about that field, but every tima I have problem in "$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));" "$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-" "$string = preg_replace('/[._]+/', '', $string);" - need to be like this Thank you again, my problem is SOLVED! Link to comment Share on other sites More sharing options...
PascalVG Posted April 29, 2014 Share Posted April 29, 2014 Thanks for the feedback. Glad it worked for you :-) I'll mark the topic as solved. Happy selling, Pascal Link to comment Share on other sites More sharing options...
dtwfung Posted August 26, 2015 Share Posted August 26, 2015 PascalVG, you are the man, thank you very much!!!! I was cheching about that field, but every tima I have problem in "$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));" "$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-" "$string = preg_replace('/[._]+/', '', $string);" - need to be like this Thank you again, my problem is SOLVED! Just what to know if rebuild index is required after making the change ?! Thanks Link to comment Share on other sites More sharing options...
skorupa Posted September 25, 2015 Share Posted September 25, 2015 great FIX and still works with Prestashop 1.6.x Link to comment Share on other sites More sharing options...
ArturV Posted December 23, 2015 Share Posted December 23, 2015 (edited) PascalVG, you are the man, thank you very much!!!! I was cheching about that field, but every tima I have problem in "$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));" "$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-" "$string = preg_replace('/[._]+/', '', $string);" - need to be like this Thank you again, my problem is SOLVED! Hello, when i do this, (PrestaShop™ 1.5.6.0) my search doesn't work at all. When i do any changes in search.php my seach doesn't work at all. What i should do ? maybe "Re-build the entire index"? Pls help Edited December 23, 2015 by ArturV (see edit history) Link to comment Share on other sites More sharing options...
Oso Posted February 12, 2016 Share Posted February 12, 2016 Gracias, funciona de lujo en prestashop 1.6 Link to comment Share on other sites More sharing options...
pranab13 Posted June 22, 2017 Share Posted June 22, 2017 (edited) Hello ! Thank you for the answer. I posted on a similar problem because I didn't find this thread before today https://www.prestashop.com/forums/topic/615102-searching-and-indexing-dashed-and-dotted-references/ and I kind of found the same solution but I need advice and a little bit more solution : I have the same problem for the reference search but it includes dashes, dots and slashes so I changed a few things and I also thought of commenting as you did but if someone has the regex that does not exclude those signs... Also, Prestashop won't index the references with only numbers and - / or . in between. It works when they are containing letters. Hence, I can't search for the numerical references. I can search for them and find the good results when when I'm putting them by hand on the sql tables search_index and search_word so I need a solution for Prestashop to index them with the other words. Help please. Edited June 22, 2017 by pranab13 (see edit history) Link to comment Share on other sites More sharing options...
avgear.shop Posted May 9, 2018 Share Posted May 9, 2018 Hello!, I need help with search engine in Presta 1.7, I hope I will find a good soul to help me out. When I want to search for example: VR-50HD, EVOLVE 50 and I type the exact same thing in the search engine, it is all perfect, same situation when I use space instead of dash (VR 50HD). The problem occurs when phrases are without any punctuation marks like VR50HD, EVOLVE50. It's like product does not exist. The use of the above modification does not repair. Another problem I got is with the results of the search engine. When searching VR-50HD, engine will add a lot of products where "50" appears in the product or even the category. Regards Link to comment Share on other sites More sharing options...
pranab13 Posted May 9, 2018 Share Posted May 9, 2018 2 minutes ago, lukaszwojcik said: Hello!, I need help with search engine in Presta 1.7, I hope I will find a good soul to help me out. When I want to search for example: VR-50HD, EVOLVE 50 and I type the exact same thing in the search engine, it is all perfect, same situation when I use space instead of dash (VR 50HD). The problem occurs when phrases are without any punctuation marks like VR50HD, EVOLVE50. It's like product does not exist. The use of the above modification does not repair. Another problem I got is with the results of the search engine. When searching VR-50HD, engine will add a lot of products where "50" appears in the product or even the category. Regards Maybe you can solve it by adding the references without the dashes as product tags "VR50HD". I did that on the 1.6 so you can try on the 1.7. Then you put a high weight of search to the tags (if this still exists on the 1.7) on the search configuration admin page. Link to comment Share on other sites More sharing options...
avgear.shop Posted May 9, 2018 Share Posted May 9, 2018 Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand. Link to comment Share on other sites More sharing options...
skorupa Posted May 9, 2018 Share Posted May 9, 2018 2 hours ago, lukaszwojcik said: Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand. Prestashop Search sucks, so if you are not attached to it I prefer searching for other solution. Payed or not. From free ones http://bradsearch.io is quite good, tested on Prestashop 1.6 maby works on 1.7 and for payed ones search on addons. Link to comment Share on other sites More sharing options...
pranab13 Posted May 11, 2018 Share Posted May 11, 2018 On 09/05/2018 at 8:18 PM, lukaszwojcik said: Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand. Yes I know that's no the best, this is at least a temporary thing. I have 8000 products but what I did is just a big excel file with a column for the references, and a column concatenated for the tags that contains the references with the dots or dashes and without (you do a big search and replace for the dashes and dots). Then I imported it. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 2, 2018 Share Posted September 2, 2018 Hello, does anyone know how to apply this fix to Prestashop 1.7.4? I'm having the same problem with - char, and I'm unable to fix it following PascalVG tip. Link to comment Share on other sites More sharing options...
pranab13 Posted September 3, 2018 Share Posted September 3, 2018 10 hours ago, DARKF3D3 said: Hello, does anyone know how to apply this fix to Prestashop 1.7.4? I'm having the same problem with - char, and I'm unable to fix it following PascalVG tip. See if my post can help you : https://www.prestashop.com/forums/topic/615102-searching-and-indexing-dashed-and-dotted-references/ It's for Prestashop 1.6.1.10 and I don't know if the class search.php is the same for the 1.7.4 but you can check. Link to comment Share on other sites More sharing options...
Peter Petrik Posted October 16, 2019 Share Posted October 16, 2019 Great, it works, try to search for example this code MJ-TAN-K-H on my site: https://skoff.sk/ Link to comment Share on other sites More sharing options...
nsm Posted January 18, 2020 Share Posted January 18, 2020 On 4/13/2014 at 2:15 PM, PascalVG said: Hi, I'm no expert on preg_replace, but I think this does it. (Not fully sure if I 'allow' too much now, though. See below) In file: Classes/Search.php (make backup, and best to make an override class and override sanitize function (see dev guide on how to) public static function sanitize($string, $id_lang, $indexation = false, $iso_code = false) { $string = trim($string); if (empty($string)) return ''; $string = Tools::strtolower(strip_tags($string)); $string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8'); $string = preg_replace('/(['.PREG_CLASS_NUMBERS.']+)['.PREG_CLASS_PUNCTUATION.']+(?=['.PREG_CLASS_NUMBERS.'])/u', '\1', $string); $string = preg_replace('/['.PREG_CLASS_SEARCH_EXCLUDE.']+/u', ' ', $string); if ($indexation) // $string = preg_replace('/[._-]+/', ' ', $string); $string = preg_replace('/[._]+/', ' ', $string); else { $string = preg_replace('/[._]+/', '', $string); // $string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string)); $string = preg_replace('/[._]+/', '', $string); // $string = preg_replace('/[^\s]-+/', '', $string); } $blacklist = Tools::strtolower(Configuration::get('PS_SEARCH_BLACKLIST', $id_lang)); As you can see, I commented-out three lines (with // ), (and I added one line, see below) The first commented-out line: // $string = preg_replace('/[._-]+/', ' ', $string); I replaced (one line below it) with: $string = preg_replace('/[._]+/', ' ', $string); As you can see, I only took out the minus sign here (red indicated in original line). This makes that the minus sign will not be replaced with a space (so not creating two separate sub words), during reindexation. The other commented-out lines are used when searching, not indexing. These two lines, as far as I can see, searches for some (sub)string with a - (minus sign), and replaced with the (sub) string only. So I just took out these replacements to keep the minus signs intact. (N.B. Not 100% sure I 'allow' too much because of this. Any preg_replace expert any comment??) See sample here: In a demo shop, I added a string to the short description of the "iPod nano" product: (go to product detail for full short description text): oopad-nonno http://ps1562.buymethai.com/en/ (N.B. link to temp testshop, may not work in future) N.B. The general restriction in search isn't changed: you can only find words that START with the given string (like 'touc' (for touch) is found, but 'ouch' not, as the search string must start with the begin letter (t) to be found) That said, Try to play with it here in the sample shop. It seems that searching for: oop oopa oopad oopad- oopad-n oopad-no oopad-non oopad-nonn oopad-nonno and oopad iPod (two words, "start with", both exist in same product) all works not works: oopadn (no - sign, so not found) oopadnonno (no - sign, so not found) nonno (nonno isn't added separately, as the only word added to the index is oopad-nonno) -nonno (the word starts with oopad, -nonno isn't indexed separately) etc. as the - sign is really part of the word, (and the word starts with oopad). (In database, there's only one index word "oopad-nonno", no variations, partial strings) Hope this does the trick, pascal. Thanks Pascal Changes work on Prestashop 1.7.4 I've been months looking for this solution until I found yours Here I leave my search.php for anyone that needs it Search.php 2 Link to comment Share on other sites More sharing options...
octb Posted March 31, 2020 Share Posted March 31, 2020 I have a similar problem with hyphens not being displayed in $product.attributes, even though in the database the text is stored correctly. Please if anyone point me to where can i look for the file where this is formatted or created. Link to comment Share on other sites More sharing options...
skorupa Posted March 31, 2020 Share Posted March 31, 2020 @octb what version of PrestaShop you are using? Link to comment Share on other sites More sharing options...
octb Posted March 31, 2020 Share Posted March 31, 2020 @skorupa 1.6.1.1 I've been looking for a solution for weeks, please let me know if you have any ideas. Link to comment Share on other sites More sharing options...
scs317 Posted April 5, 2022 Share Posted April 5, 2022 What a relief to have found this topic! We have the same problem on PS 1.7.6.9 - Do you know if the file posted by "nsm" (1.7.4) works or is compatible? Also, we've heard that newer versions of PS handle the hyphen as an independent character by default, what do you think? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now