Jump to content

[Override] Strict and only relevant searching in Prestashop for free


hakeryk2
 Share

Recommended Posts

Hello devs and users,

I was strugling with this really bad behavior of Prestashop search engine when ie: you were searching for "wooden chair" and You end up with result of products that contains "wooden" and "chair" as well. Which sucks ass.

This was driving my crazy so I end up with this override for Search.php in Prestashop 1.6 - didn't tested this on 1.7. This piece of code checks whether product that You searched for contains both or more words in search index (like tags, featuers not only the name) that You actually searched. Now I can die peacefully because when somone was searching for ie: Black chair he don't ends up with bunch of black wardrobes, chairs, sofas etc but actually only black chairs.

To get this working at least in a relevant way please use at least (product name, features, categories, tags) or combinations set in Preferences -> Search. After this rebuild Your cache. Try not to use description or short description because it contains to many words.

To install this just put this file in override/classes/ and after this remove class_index.php file in cache folder.

I hope You find it usefull. I was working on this for 6 hours because I had to understand how prestashop search engine works (by the way - why the f*** presta needs to get all products from shop before searching!?) and I had to do this as efficient and performative as I can so any tip will be appreciated. It works faster for me then previous one. Try it for yourself :) If someone will find a better way to do this after reading this code please share it as well.

I need to edit the file because previous contained a lot of my own overrides to search categories, cms and other stuff as well - now it's a clean one :)
Update: I found much more efficient and easier method to get this done :) Edited again.

 

 

 

Search.php

Edited by hakeryk2 (see edit history)
  • Like 5

Share this post


Link to post
Share on other sites

You need to remove class_index.php file from cache folder after putting this override.

It works for 1.6 - I didn't tested this on 1.7 but I think that devs can edit this without any problem to 1.7 and share with it here as well.

  • Thanks 1

Share this post


Link to post
Share on other sites

I don't know if its my PS only (PS 1.7.6.4), but search results are not filtered by reference number. If I have a product with 10 combinations for example: 

C100-00 -> default combination

C100-01, C100-02, C100-03 ....etc. are other combinations. If I search for the combination C100-03, the search result brings me the default C100-00 combination option (links to default combination). That may be confusing for customers. I'd like to know if you have this problem solved.

 

Best regards! 

Edited by Ezequielb (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hi! Thanks a lot for your work! It solved half my issues. My PHP and SQL years are far away. Using your code, how could I exclude products of a category from the search results? A fast and dirty hack using a hard coded category id on line 95 wouldn't bother me.

Best regards !

Share this post


Link to post
Share on other sites

On 4/18/2020 at 2:56 PM, Ezequielb said:

I don't know if its my PS only (PS 1.7.6.4), but search results are not filtered by reference number. If I have a product with 10 combinations for example: 

C100-00 -> default combination

C100-01, C100-02, C100-03 ....etc. are other combinations. If I search for the combination C100-03, the search result brings me the default C100-00 combination option (links to default combination). That may be confusing for customers. I'd like to know if you have this problem solved.

 

Best regards! 

Nobody?

Share this post


Link to post
Share on other sites

Just to let You know folks - I edited this solution to be more effective. It is still precise but it can do more and faster. Feel free to upgrade it. Original file from first post is the one updated.

First solution had much more queries then it suposse to has :)

Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites

I updated right now the top version but I cannot help You until You don't provide me an error from logs which You received. For 1.6.1.24 is working, I didn't test on 1.7 and I think it might be an issue because on 1.7.7 they added some new functionalities to search engine so even if You have lower version then it might be not the best thing for you.

Share this post


Link to post
Share on other sites

Thanks for this - I will give it a go and give some feedback

We've also been struggling - search was overloading our server, causing resource blocking - resulting in limited connections, resulting in errors

- Andrew

Share this post


Link to post
Share on other sites

Currently I am working on cache system for this to be able to cache most popular search results. I will upload this feature in some near future but any help will be appreciated.

 

Damn, customers are really happy because they can find products not by their name but just by typing everything related to product :) 

Share this post


Link to post
Share on other sites

  • 3 months later...

Hi,

I have moved the file to override/classes/  in my 1.7.6.2 version an as you advised deleted: /var/cache/prod/class_index.php. 

I can't see any changes in the search engine behaviour still works like before.

I think this solution stull need a bit more work to suit PrestaShop 1.7

Thanks 

Edited by Maryando (see edit history)

Share this post


Link to post
Share on other sites

  • 2 months later...
  • 1 month later...
On 4/6/2020 at 6:34 PM, hakeryk2 said:

Hello devs and users,

I was strugling with this really bad behavior of Prestashop search engine when ie: you were searching for "wooden chair" and You end up with result of products that contains "wooden" and "chair" as well. Which sucks ass.

This was driving my crazy so I end up with this override for Search.php in Prestashop 1.6 - didn't tested this on 1.7. This piece of code checks whether product that You searched for contains both or more words in search index (like tags, featuers not only the name) that You actually searched. Now I can die peacefully because when somone was searching for ie: Black chair he don't ends up with bunch of black wardrobes, chairs, sofas etc but actually only black chairs.

To get this working at least in a relevant way please use at least (product name, features, categories, tags) or combinations set in Preferences -> Search. After this rebuild Your cache. Try not to use description or short description because it contains to many words.

To install this just put this file in override/classes/ and after this remove class_index.php file in cache folder.

I hope You find it usefull. I was working on this for 6 hours because I had to understand how prestashop search engine works (by the way - why the f*** presta needs to get all products from shop before searching!?) and I had to do this as efficient and performative as I can so any tip will be appreciated. It works faster for me then previous one. Try it for yourself :) If someone will find a better way to do this after reading this code please share it as well.

I need to edit the file because previous contained a lot of my own overrides to search categories, cms and other stuff as well - now it's a clean one :)
Update: I found much more efficient and easier method to get this done :) Edited again.

 

 

 

Search.php 9.03 kB · 35 downloads

[edit]

i have an error 500 with 1.61.13

Edited by ukyoner (see edit history)

Share this post


Link to post
Share on other sites

  • 2 months later...

@hakeryk2 can you solve this issue?

When you search for a product using the reference number with a product that has 10 combinations and each combination has a reference number, the search results do not take you to the correct reference number but to the default combination.

Can you shred some light to find a solution for this?

 

Best regards!

Share this post


Link to post
Share on other sites

  • 3 weeks 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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More