Jump to content

Partial search does not work


Recommended Posts

The partial search in Prestashop seems broken. I have found 3 threads with the same problem as mine.

 

http://www.prestashop.com/forums/topic/49430-search-not-working-right/?hl=%2Bpartial+%2Bsearch&do=findComment&comment=330576

http://www.prestashop.com/forums/topic/89997-search-problem/?hl=%2Bpartial+%2Bsearch

http://www.prestashop.com/forums/topic/100766-partial-searches/?hl=%2Bpartial+%2Bsearch

 

There is also a bug report:

 

http://forge.prestashop.com/browse/PSCFV-11576

 

For example I have the word "Holzschatulle". If I type in "schatulle" it does not find the word "Holzschatulle". 

 

Does anyone know a workaround? Alternatively where can I change the query string? In /classes/Search.php ?

Link to comment
Share on other sites

  • 1 month later...

I forgot to mention how I solved it. You have to open /YourPrestashopRoot/classes/Search.php

 

Go to the find() function. There change the first foreach() loop to this:

 

foreach ($words as $key => $word)
if (!empty($word) && strlen($word) >= (int)Configuration::get('PS_SEARCH_MINWORDLEN'))
{
$word = str_replace('%', '\\%', $word);
$word = str_replace('_', '\\_', $word);
$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)).'%\''
);


if ($word[0] != '-')
$score_array[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';
}

There is not much change except that I added 2 or 3 %-characters. This fixes the problem. I use Prestashop 1.6.

Edited by Barama (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...