Developer Tips: How Prestashop Search Works

May 17, 2012798Alex Simonchik

Search is an integral component of any eCommerce project. The more efficient it is, the better seller’s business is doing. Search significance is proven by a huge success of Google – a company that provides relevant answers for user requests. Today we will examine technical features of Prestashop search and share details, available for average users.


Back Office -> Preferences -> Search part is configured by users and provides opportunities for search to be adjusted flexibly.

On the picture above, the system performance will be high in any case since the number of products in the directory is small. But there are projects, in which the directory is very large and among the variety of products customers need to find the one that matches their request precisely.

Indexed products parameter indicates the amount of products from the catalog that are available. There are two links: Add missing products to index and Re-build entire index. The former activates the process of indexation, upon completion of which index includes products that were absent for some reason. The latter clears search_index and search_word tables and sets the «indexed» flag for all items in the product table to zero. Then a complete re-indexation occurs. It’s desirable to configure a cron job for re-indexation at the time when site traffic is low and the server load is minimal. The process of re-indexation is very resource-intensive as far as each non-indexed product is processed one by one, language by language, although the products are processed 50 by 50 in order to avoid overloading MySQL.

Ajax search allows displaying search results “on the fly”, i.e. when the user enters a search query, which exceeds the Minimum word length value, the server receives the request and search results are shown in a dropdown menu. Blacklisted words help adding words to be extracted from (Seacrh :: sanitize ($ string, $ id_lang, $ indexation = false)), for instance, prepositions or obscenities. This will reduce the weight of the table with indexed words.

Instant search derives results not to the dropdown list, but displays them “on the fly” in the directory.

Weight section allows setting priorities for search requests, i.e. items with search words in the Reference field will appear higher than products, containing the same word in the Description field.

This is the required minimum for users to know. Now we will take a closer look at the technical side of search and indexation. The static function Search :: indexation ($ full = false, $ id_product = false) is responsible for the process of indexation and $weightArray is in charge of index fields and search priorities. Indexation is running through necessary fields in different tables and picks out the data. Then each sentence is divided into words, words from the Blacklist and those less than Minimum word length are removed and data is saved to search_word table. The image below introduces the result of indexation of seven products, reflected in 1551 in the search_word table!

This is the structure of the main tables, involved in the search:

The search_word table stores indexed keywords for each language. They are connected through the id_word field with the search_index table, where their priorities and products they are related to are defined.

If you need to insert another field to the index, it should be brought to the $weightArray and added to the SQL request. The code below adds location field  to the index field.


The Search :: find ($ id_lang, $ expr, $ pageNumber = 1, $ pageSize = 1, $ orderBy = ‘position’, $ orderWay = ‘desc’, $ ajax = false, $ useCookie = true) function performs the search. It analyzes the search request, removing characters less than Minimum word length, and finally performs the search. It should be noted that Ajax and standard search are done by different SQL requests.

Expect to read about changing Prestashop standard search to sphinx soon.


  1. Why i have indexed products 1138/1139… where is the other product? is a frequently bug or what happens?

  2. jorgevrgs,

    There are still no products after reindexation? The problem may be that products are saved wrongly.

  3. Hey, thanks for the article – very informative! If I understand this correctly, you cannot limit search to single specific field (that the user chooses) with the default setup. So, if one were to allow the visitor to search in only name or only short description – can’t I just search the product table directly? Or does the pair of index table improve search performance in addition to implementing the weight system?

  4. RickM,

    Yes, search sadly operates with the whole index table no matter what you search for – for instance, in names only. In order to search in only name the search module should be modified substantially. Indexation as well as search engine logic itself should be changed.

  5. hello alex, hope you are great, my question is how do i hide or eliminate the value “search”? i don´t want to show “search” in the button submit.

    thanks for your help


  6. Citlalli,

    not sure if I understood you properly, but if you do not want to have the Submit button, simply delete it from the file


  7. Hi Alex,

    Thanks for this nice post

    Is writing a post about using sphinx search whith prestashop is still planned ?

    Thanks in advance.


  8. Thank you, Antoine. This is quite an interesting topic, however, unfortunately, I have no experience with sphinx yet. But as soon as get it I will be glad to share it with the community.

  9. Hallo,
    i’m working from 2 weeks with presta 1.6 coming from older versions.

    I think is good but i got a problem.
    I’m preparing a site to sell toner and inkjet cartridges.

    I index all the products and i got no error.

    I make an example to explain what’s happens:
    i got a product that hasi in description “TONER CARTRIDGE FOR HP 1010 – OEM CODE Q2612A”

    if i search for 1010 i find it
    if i search for q2612a i find it
    if i search for 2612 no result

    It works in “like” mode but it seems that it wants a complete word. This is a big problem becaouse I can’t be sure about the customer will search for.

    Can anybody help?


  10. Luca,

    look for sql request in Search::find() method and you’ll see that request looks like LIKE ‘2612%’, but you need change it to LIKE ‘%2612%’.

  11. Hi Alex,

    Thank you for the information.
    Do you know if it’s possible to show results according to every category selected in the product?
    Now it shows only products for their “default category” but not for all the categories selected.

    For example I have a subcategory called “mamparas abatibles” with 2 products but if I write “mamparas abatibles” in the search box doesnt show any result because these two products have another “default category”.

    Thank you very much!

  12. Hello Alex, has there been an update to this post on July 8: “In a few days I will post an article and will attach a module to include ‘supplier name’ into search.”
    In addition, is there a module to search the CMS pages? Thanks!

  13. Hello,
    I would like to track customer search in my shop in a such way if there is no search result found then system should make an entry of that search word in separate table so I can review them later. How can I proceed with this?

  14. Hi Alex. thank you for the informative article.

    I wonder when you said that indexation function takes a sentence by sentence and then cuts those sentences into words in order to populate search_word table…

    What do you mean by “sentence”?

    Is it a string of some predefined char length?

    I’m asking because on some products in our shop, we have literally thousands of words listed in the description field and they are literally in a list

    Here is the example:

  15. hi. 1 product title = PHILIPS Satinelle Epilator HP6420. when type in the 6420 only, and press enter, message “No results were found for your search “6420”. how to make it work? thank you.

  16. tim,

    You can ask our support team for the solution ( But in general the search can be changed as you want and even sphinx can be used, but it is not a subject for the article.

  17. I am facing problem in indexing products to search. I have around 2200 products which will increase upto 20000.

    When ever I try to index products using Corn, rebuild index or add missing product to index – the site give 500 error sometime after indexing 300-400 products sometimes more. I use backslash to reopen admin but sometimes add missing product to search work, sometimes not. Maximum no. of product I am able to add is 1400 that too only once. My developer tried to increase time interval etc. but could not get any success. Is there any way to index 20000 or more products to search index OR is there any way to use frontend search without indexing the products by making some changes in search.php file.

    Thanking you

  18. @Anshul you should check how index process loads your server resources. It’s hard to give some advice without knowing server infrastructure, active processes, etc.

    If you need help, you can contact our support team at

  19. Hi,

    My shop is built with Prestashop 1.5.6.

    The shop has around 2000 products, with an average of 10 combinations per product.

    Therefore, some processes in the Back Office take time.

    As an example, when we want to create an order from the BO, searching for the product can take up to one minute.
    In the BO, the same trouble occurs when we want to add a product to an existing order.

    Is there a way to increase the search of a product in the Back Office, in the AdminOrders page ?

    I think this search process is related to :

    the ajaxProcessSearchProducts function in controllers/adminorderscontroller.php
    and the searchByName function in classes/Product.php

    But, unfortunately, I have no skill to amend such functions in the way to increase the search speed.

    Thank you in advance for any suggestion.


  20. Hi Alex,
    I setup a shop using prestashop, I have two user groups namely A & B. Either user group has access to some of the category (products) of other group. When i search for a product of group B, after logged in as a group A user i still see the product. In reality i should see an error. How can i achieve this? please help

  21. Hi,
    I have prestashop 1.6 and about 1080000 products. If I run: ” Add missing products to the index ” and about 320000 product are indexed, all works fine.
    But if is indexed more than about 400000 products searching not working and presta write error message: “prestashop Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes)”

    I use 256MB and max exec time is 600s
    Can you help me please?
    PS: sorry for my english

  22. Hi,
    I have presta yesterday for some reason the search engine don’t finds the some new product that we have adds. I have make reindexing from menu preferensces->search and now it find very few products. I have Indexed products 2611 / 2611.
    And all the other seem to be well. What can I do?

    Thanks in advances

  23. Hi Poukamisas Vasilis,
    It’s necessary to investigate your case, probably there is a problem with some custom module you have, or some database issues. Anyway you can contact our support team at

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *