Jump to content

Search in title doesn't work correctly


Recommended Posts

Hi,

I have a little problem with prestashop search engine. I use 1.4.9 version and for example i have a product "yamaha rx-v373".

If i type in search box the product name, it appears but if i type for example v373 or just 373 doesn';t show me this product.

 

I set the product Product name weight to 10 in Preferences--> Searh and Minimum word length to 1.

I have reindexd the products but no result. Please can someone advise me if is a simple method to solve this? otherwise i should change the search php to search only in title.

 

PS in backend if i type 373 or v373 it works, the product appears.

 

Thanks

Stefan.

Link to comment
Share on other sites

You can define search aliases in back office.I know this does not solve the problem completely, but until you solve the problem, you can use this as a temporary solution.

Thanks, you have right, is just a temoporary solution, i have at least 4000 products and many of them are simillar, i can't do it manually for all of them.

Edited by prunica (see edit history)
Link to comment
Share on other sites

To solve this problem open the file

classes/Search.php

 

Search the "find" function. There you will have something like

 

$intersectArray[] = 'SELECT 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.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] != '-')

$scoreArray[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

 

 

If you know some MySQL, you'll guess that this query searches only words starting with your searched term. In order to make it search words that start with it, but, also, end with it. So, you have to add 3 '%'

characters after every like. So, the code will be:

 

$intersectArray[] = 'SELECT 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.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] != '-')

$scoreArray[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

Link to comment
Share on other sites

  • 6 months later...
  • 1 month later...
×
×
  • Create New...