I found out a problem. If your store has a product with an article ABC12345, you can find it inserting in search field ABC12345, ABC123, ABC1 and so on. But if you write there 12345 or 123, there’s going to be no results. Regular phrases like * do not work. Is there any other way to find product with 12345?
I have a solution. We need to redefine method find of Search class. In sql-request that does the search process you need to add %-symbol at the beginning of the line, that we are searching for. Find in file classes/Search.php this code:
1 2 3 4 5 6 7 8 9 10 |
$intersect_array[] = 'SELECT si.id_product FROM '._DB_PREFIX_.'search_word sw LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = '.(int)$id_lang.' AND sw.id_shop = '.$context->shop->id.' AND sw.word LIKE '.($word[0] == '-' ? ' \''.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' : '\''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' ); |
And change it for that:
1 2 3 4 5 6 7 8 9 10 |
$intersect_array[] = 'SELECT si.id_product FROM '._DB_PREFIX_.'search_word sw LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = '.(int)$id_lang.' AND sw.id_shop = '.$context->shop->id.' AND sw.word LIKE '.($word[0] == '-' ? ' \'%'.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' : '\'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' ); |
It’s better to override the file classes/Search.php.
I have this part of the code from 209th line.
Hi, Luca!
It is impossible to improve search in such a way you are talking about through the admin panel of PrestaShop. It can be done by code changing.
Please, contact our support team [email protected]. They will help you with this problem.
I’ve a problem with 1.6
Search engine is a disaster. If you search for “woman orange shirt” it shows a lot of irrelevant results because it will find any product that contains just one single word: woman, orange, shirt.
It’s a OR and not an AND search.
Is there any way to improve search and let it show ONLY the exact phrase?
Hope you can help me
Thanks
@f288
If you made modifications with an override, you had to delete your class_index file.
I’m followed your guide but it seems that nothing happened on PS1.6.0.9.
I also tried to empty the cache. There’s something else that i should do?
Александр,
Спасибо!
чуть ниже тоже желательно поправить
if ($word[0] != ‘-‘)
$score_array[] = ‘sw.word LIKE \’%’.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).’%\”;