Backend Search Data: How To Get Visible Objects While Using Search in Pimcore

Did you ever find yourself in a situation where there are no visible objects when you click on the search icon in Pimcore or while using global search? Are you curious about what is actually searched and why Pimcore returns results fast among millions of objects? If you are nodding affirmative, continue reading and find out how to get visible objects while using search in Pimcore. 

 

This is the situation where a table called search_backend_data comes into the work. Firstly, let's examine how does this table look like.

 

 

As you can see, a couple of indexes are in this table. The most important ones are data and properties; they both use the Full-text index. Since Full-text search is complex and very powerful, make sure to read more about Full-text search on this link and on the Josh Graham blog, where he explained it further. 

How Pimcore Utilizes Backend Search Data Feature

 

The idea is to put everything that could be searched from objects/assets/documents into search_backend_data as data or properties. Now, let's examine what it stores as data in the database. To do that, we will create a class called "test" for testing purposes.

 

Whenever we store an object, the search_backend data will not be populated immediately. Instead, a messenger_messages table will be populated with the details of which row needs to be created to populate the search_backend_data. So, storing the data in the table happens asynchronously in the background. 

If we would store the object above and if we check the messenger_messages table, we will see something like this: 

 

O:36:\"Symfony\\Component\\Messenger\\Envelope\":2:{s:44:\"\0Symfony\\Component\\Messenger\\Envelope\0stamps\";a:1:{s:46:\"Symfony\\Component\\Messenger\\Stamp\\BusNameStamp\";a:1:{i:0;O:46:\"Symfony\\Component\\Messenger\\Stamp\\BusNameStamp\":1:{s:55:\"\0Symfony\\Component\\Messenger\\Stamp\\BusNameStamp\0busName\";s:26:\"messenger.bus.pimcore-core\";}}}s:45:\"\0Symfony\\Component\\Messenger\\Envelope\0message\";O:38:\"Pimcore\\Messenger\\SearchBackendMessage\":2:{s:7:\"\0*\0type\";s:6:\"object\";s:5:\"\0*\0id\";i:218932;}}

 

So, in order to store the data in search_backend data, Pimcore's SearchBackendHandler needs to be invoked. The SearchBackendHandler is simply a symphony class that responds to the event in the background. 

The important thing here is that from Pimcore's documentation, cron job op supervisor needs to be set in order to consume messages: 

 

*/5 * * * * /your/project/bin/console messenger:consume pimcore_core pimcore_maintenance pimcore_image_optimize --time-limit=300

 

After the cronjob has been invoked and we have maintenance set up correctly in Pimcore, we should be able to see newly created class data in a search_backend_data table. 

If you missed it or don't have a maintenance setup, you can read about supervisor/cronjob in Pimcore's Development Documentation.  

We should be able to see new records in search_backend_data shortly. 

The data columns should contain all of the data we entered in our Test object. 

I still don't see my data despite the cronjob/supervisor set

 

It can occur that search_backend_data is missing some rows due to a couple of reasons.

  1. Migrating database without search_backend_data cause it can sometimes be too big. 

  2. Manually modifying the data through the database.

  3. Misconfiguration in supervisor/cronjob.

If all the 3 points above are confirmed that they should work, we can use one last command: ./bin/console pimcore:search-backend-reindex

This command, if run, will go through each object and index it.

 

Do you have more questions, or you're having issues while implementing this? Feel free to reach out; we'll be happy to help!

Looking for Exponential Growth? Let’s Get Started.
Explore next

Pimcore Tutorial

Check out our step-by-step tutorials on how to use Pimcore features and solutions.

Discover more