Peter_S83 Posted January 15, 2020 Share Posted January 15, 2020 I got a big problem, don’t know if somebody can help. The search is shitty, total shitty and it is because of the products names, but other shops solved it better. The problem is, search for a product on the side named "Mi 9" (with a space in between) you will find https://presta.tradingshenzhen.com/en/search?controller=search&orderby=position&orderway=desc&search_category=all&s=mi+9 160 products, which is totally shitty. Because he searches first for the name „Mi“ and adds than the 9, but shows all products that start with a „Mi“ and this are nearly every product from Xiaomi. Even when I set it to exact search, even if I make alias that say if I enter „Mi 9“ search for „Mi9“ because article reference numbers have usually the name in it, but together written. So for example 10405/6GB/128GB/Mi9/CHN Any idea how I could fix it. If I enter „Mi9“ written together, I will find 11 products and this is perfect, but most of the customers write „Mi 9“ with a space in between. https://presta.tradingshenzhen.com/en/search?controller=search&orderby=position&orderway=desc&search_category=all&s=mi9 My settings are Prestashop 1.7.6.2 a fresh installation, nothing in it, except the products and a custom theme Search Alias mi 9 -> mi9 | mi+9 -> mi9 | Search within word - deactivated (when I activate it, I get 373 results) Search exact end match - activated (when I deactivate it, I get 215 search results) Minimum word length (in characters) = 2 (I had before 3, but it found nothing when you type Mi 9 because he sees the Mi and things this are 2 letters and as it isn't 3, he finds nothing) Product name weight = 10 Reference weight = 5 tried also Tags weight but it doesn't help, he also sees mi and a space as a hit, so if you set Tags weight to 10 and all other to 0 and you enter "Mi 9" he also shows products like "Mi Bluetooth Speaker" or "Mi Pro 15.6 Notebook" because of the Mi. I will pay if somebody finds a solution for this problem, I am so frustrated. 1 Link to comment Share on other sites More sharing options...
EvaF Posted January 16, 2020 Share Posted January 16, 2020 I would personally solve it by the next way: ( I prefer the overriding of Tools, Search and SearchController, but it is up to you) I would prepare the removeSpaceAtDigit function in Tools such a like as 1) public static function removeSpaceAtDigit($string) { // $string = 'Mi 9 fdkfjdks dMi 8'; $pattern = '/(\w+) (\d+)/i'; $replacement = '$1$2'; return preg_replace($pattern, $replacement, $string); // result = 'Mi9 fdkfjdks dMi8' } 2) further i would override ( or change) the fillProductArray function in Search protected static function fillProductArray(&$product_array, $weight_array, $key, $value, $id_lang, $iso_code) { if (strncmp($key, 'id_', 3) && isset($weight_array[$key])) { //------------ added one line ------------------------------ $value = Tools::removeSpaceAtDigit($value); // --------------------------------------------------------- $words = Search::extractKeyWords($value, (int) $id_lang, true, $iso_code); foreach ($words as $word) { if (!empty($word)) { $word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH); if (!isset($product_array[$word])) { $product_array[$word] = 0; } $product_array[$word] += $weight_array[$key]; } } } } 3) I would modify the search string the same way as above - it means overriding ( or change) the getProductSearchQuery function in SearchController protected function getProductSearchQuery() { $query = new ProductSearchQuery(); $query ->setSortOrder(new SortOrder('product', 'position', 'desc')) // -------------- modified line ---------------------------- ->setSearchString(Tools::removeSpaceAtDigit($this->search_string)) // --------------------------------------------------------- ->setSearchTag($this->search_tag); return $query; } 4) ensure search indexation ( f.e. in CONFIGURE->Search->You can set a cron job that will rebuild your index using the following URL:) Link to comment Share on other sites More sharing options...
Peter_S83 Posted January 16, 2020 Author Share Posted January 16, 2020 tried it, wasn't the solution I offer 50-80€ if somebody can find a solution for me Link to comment Share on other sites More sharing options...
Peter_S83 Posted January 17, 2020 Author Share Posted January 17, 2020 Solved by EvaF AWESOME, love you Link to comment Share on other sites More sharing options...
airjohn Posted April 3, 2023 Share Posted April 3, 2023 Can you share the solution for us too? Is it finally solved with what EvaF posted here or with the extra 50-80€? Link to comment Share on other sites More sharing options...
TiaNex Shopping Posted April 4, 2023 Share Posted April 4, 2023 wang zhan zuo de tinghao 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