Get Free Audit

Developer Tips: How Prestashop Search Works

May 17, 2012

5165 Alex 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.

Igor Dragun

Partner With Us

Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

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.


PrestaShop Development

Take your online store to the next level with BelVG PrestaShop Development

Visit the page

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!

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

This is the structure of the main tables, involved in the search:p style=”text-align: justify;”>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.

// All the product not yet indexed are retrieved
$products = $db->ExecuteS(‘
SELECT p.id_product, pl.id_lang, pname, p.reference, p.ean13, p.upc, pl.description_short, pl.description, cname, mname, p.location
FROM ‘._DB_PREFIX_.’product p
LEFT JOIN ‘._DB_PREFIX_.’product_lang pl ON p.id_product = pl.id_product
LEFT JOIN ‘._DB_PREFIX_.’category_lang cl ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang)
LEFT JOIN ‘._DB_PREFIX_.’manufacturer m ON m.id_manufacturer = p.id_manufacturer
WHERE p.indexed = 0’, false);

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.


PrestaShop Support

Take your online store to the next level with BelVG PrestaShop Support

Visit the page

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor


  1. 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 [email protected]

  2. 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

  3. 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

  4. 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

  5. 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.


  6. 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

  7. tim,

    You can ask our support team for the solution ([email protected]). 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.

  8. 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.

  9. 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:

  10. 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?

  11. 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!

  12. 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!

  13. 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%’.

  14. 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?


  15. 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.

  16. Hi Alex,

    Thanks for this nice post

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

    Thanks in advance.


  17. 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


  18. 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


  19. 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.

  20. 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?

  21. jorgevrgs,

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

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

  23. Very nice article!!! Thank you.

    I have a question, though.

    Assume that I have a product with reference “STAR – 123”

    If I search “STAR – 123”, a result is found but if I search “STAR-123” removing the spaces, no result. Similary, if I search “”STAR123” removing the dash and spaces, no result again. Then if we try “S- TAR – 123” adding a new dash and space, again, no result.

    But many customers make their searches by entering what they remember. They don’t pay attention to punctuation.

    How can I overcome this problem?


  24. Terry,

    As a workaround, you can set customize logic: if your search is used only to search for code it is possible, for example, to remove all spaces. Or to create one additional field where users shall enter their code and to remove spaces there.

  25. François,

    This happens because SQL query takes into account the id_lang parameter, which contains the language id of your current locale. To make search in the way you want it, you need to remove this parameter by overriding Search::find()

    You need to remove id_lang in the following parts:


  26. Ron,

    Sorry for the late response. In a few days I will post an article and will attach a module to include ‘supplier name’ into search.

  27. Hello and thank you for the article!

    I have a question about the search function in Prestashop.

    If i have a product code of GBH26VLI how can I have prestashop find it also by variations of the code, liek GBH 26, GBH 26VLI etc without adding tags??

  28. Alex,

    Thanks for this very usefull post.
    I’d like to ask you an advice to solve the following problem:
    My site is french and russian. Every product as title and attributes in french (or latin transcript) and russian (cyrillic).
    When I search a word written in cyrillic in the french interface there is no result. When I search the same word in the russian interface I have results. (and same problem in the other way when searching latin words in russian interface)
    How could it be possible to “liberate” the searched fields from the current FO language ?

    Thanks in advance !

  29. Alex, we’re wanting to be able to search by supplier name also. To include supplier name as you did with the location field (from your previous post) would you go about that same premise to be able to search on supplier name (overriding Search: getProductsToIndex and indexation) ? Thanks.

  30. Giovanni

    You need to override 2 functions of the class Search: getProductsToIndex and indexation.

    In the function getPrоduсtsTоIndex you need to define the fields which will participate in creating an array for indexing:

    In the method, which is directly responsible for indexing, you need to remove tags and features from the index. As for the attributes – I would recommend to leave them.

    After that, you need to reindex.

  31. Hi Alex, thanks for your nice article.
    You know how I can set up the prestashop search engine to search only in the title of the product?

  32. Sara,

    There is no standard possibility, but you can override Search :: indexation method so that the id_product field could get in the index as well.

  33. Hi, I would like to search for the ID also, is that possible? And how?? I am new to PrestaShop…

    // Sara

  34. Javier,

    Prestashop cannot do that as there is no such thing as default advanced search, which would specify such patameters.

  35. Nice article. What about if we would like to get results just from 1 category? Could Prestashop do that?

  36. Hi, i have 260 000 products, and the search index can’t search everything (just 20 000) do you have any idea to force this ?

  37. This is good, but the search function is entirely about products. What about when a customers wants to search something from CMS pages?

Post a new comment

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