Tweaking prestashop search – searching by products codes (reference)

Prestashop search engine is based on individual words stored in the database. It will return no results for incomplete (partial) words.

This problem was recently encountered on a website selling quad spare parts. Every spare part has a reference number in the form xxxxyyyzzzz where xxxx is specific for group , yyy for subgroup and zzzz for the product itself. Searching for “xxxx polaris” should return all spareparts belonging to the the group “xxxx” and matching the word polaris. But, as mentioned above, “xxxx” is only an incomplete word and will be normally ignored by the search engine. A simple solution is adding several lines of code into the indexation method of the Search class and rebuild the index:

if($key == ‘reference’) {
for($i = 5; $i < 10; $i++) {
if(strlen($value) > $i) {