Jump to content

How PrestaShop search feature works?


Recommended Posts

I'm quite puzzle how the search features works, especially for more than one word keywords. Sometimes it give the correct result, sometimes not.

I set up a shop, located in here: http://shayna-alexis.com/shop/. Every time I search for "mud pie" (which is one of the brand), it give wrong result. I already make sure at least one "mud pie" word written in description and/or short description.

Can somebody explain to me the syntax PrestaShop use to query the database?
Should it be something like this:

SELECT *
FROM `ps_product_lang`
WHERE `description` LIKE '%mud pie%'



If I want to change how the search feature works, can you give me the name of the file and which function should I change?

Thank you, any help will be appreciated..
Jay

Link to comment
Share on other sites

Apparently I'm opening the wrong file. The correct file should be /classes/Search.php

The default search function split the keywords (same as OR) I assume. And it use '%' sign, so it should show up the correct result right? Why the example in my first post doesn't work?

Link to comment
Share on other sites

After reading MySQL manual and do some Googling, I found out it related to Full Text Search (FTS) feature which only works for at least 4 character (ft_min_word_len variable). Since I'm in shared hosting, I can't change this. So I disable the FTS feature, and the search feature works as I intended.

Anybody have better idea than disable the FTS?

Link to comment
Share on other sites

  • 2 weeks later...

If you're using Prestashop 1.1 (my version when I started this thread), the solution quite easy.
open file /classes/Search.php, and there;s 2 lines you need to modified: line 26 & 64. On these 2 lines the code is:

case 'MySQL'



change to:

case '-MySQL'



this trick will make prestashop thinks you didn't use MySQL and hence doesn't use FTS feature (only use standard search query).

In prestashop 1.2 (I just upgraded last week) the search feature has been revamped. It doesn't use FTS (CMIIW), and in the table ps_configuration there is configuration of min word length (PS_SEARCH_MINWORDLEN) which is by default is 3. But the problem is, it works in the admin section for 3 letters words but doesn't work on the front end.

What I also found strange, the max word length is hard coded in Search.php:

define('PS_SEARCH_MAX_WORD_LENGTH', 15);



also the naming convention of the constant slightly different (notice the '_' sign).

I'm not sure if it's a bug in 1.2

So far I can't make the front end works for searching 3 letter words on 1.2

Link to comment
Share on other sites

  • 6 months later...
If you're using Prestashop 1.1 (my version when I started this thread), the solution quite easy.
open file /classes/Search.php, and there;s 2 lines you need to modified: line 26 & 64. On these 2 lines the code is:
case 'MySQL'



change to:

case '-MySQL'



this trick will make prestashop thinks you didn't use MySQL and hence doesn't use FTS feature (only use standard search query).

In prestashop 1.2 (I just upgraded last week) the search feature has been revamped. It doesn't use FTS (CMIIW), and in the table ps_configuration there is configuration of min word length (PS_SEARCH_MINWORDLEN) which is by default is 3. But the problem is, it works in the admin section for 3 letters words but doesn't work on the front end.

What I also found strange, the max word length is hard coded in Search.php:

define('PS_SEARCH_MAX_WORD_LENGTH', 15);



also the naming convention of the constant slightly different (notice the '_' sign).

I'm not sure if it's a bug in 1.2

So far I can't make the front end works for searching 3 letter words on 1.2




Many thanks Blaszta !! it works really well now on 1105 !!!

Good job ;)
Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...