In this article, we will review on how to add a Magento 2 Custom Search Engine.
By default, magento2 uses MySQL full text for search operations, but is MySQL enough to handle the huge amount of data with complex queries? The answer is no, in the competitive world speed can give you a huge plus over other competitors, and if you have a huge amount of data that needed to be searched in real time MySQL can set you back, but if you have a small amount of data MySQL will do good for you. So let’s see how we can replace mysql search engine in magento2.
How To Make a Custom Search Engine in Magento2
There are several options that you can choose to switch from MySQL search, such as elastic search, solr search, amazon cloud search etc, but we are talking about replacing an already build sophisticated search engine but the best thing about magento2 code structure is it is highly scalable, and build with components that you can easily replace with new technologies. So let’s see how we can switch from MySQL search engine to any other search engine, suppose we want to replace MySQL search with the elastic search.
I am assuming that you already know how to build a module in magento2, so lets start :
Create di.xml file:
create a di.xml file at the path app/code/CompanyName/ModuleName/etc/di.xml and add this type configuration:
<argument name=“engines” xsi:type=“array”>
<item name=“elastic” xsi:type=“string”>Elastic</item>
in the above type configuration, you can see I have inserted a string elastic in the engines array of class “Magento\Search\Model\Adminhtml\System\Config\Source\Engine” this class is responsible for rendering search engine options in magento2 stores > configuration > catalog > storefront > catalog search > search engine :
After you have added the entry in di.xml, it will start showing elastic in the search engine select box like this:
By just saving the elastic option here in the config you have managed to change the MySQL search engine, now you need to add your own logic to index data on the elastic server and then search from there.
You can learn more using Magento 2 Custom Search Engine from the video
An easy way to do this is to use the Expertrec Site Search Module.
Expertrec Site Search extension adds fast search autocomplete, spell correct and instant search results page with facets and filters that help user’s find products through the search bar much faster. Search results show up for every search keystroke that the user enters into the search bar. The extension can be used if you want to add a visual search experience to the default Magento search.
- Super fast search – With Expertrec Site Search, search results show up as soon as the user types in the first search character. There is no delay due to our low latency serving systems at the backend.
- Spell correct– Don’t worry about users making spelling errors. Our search engine automatically corrects them to the nearest product match.
- Product images in search– Give a visual search experience to your site search users. Expertrec Site Search extension shows search results alongside product matches in the search UI.
- Facets and filtering- Users can use the facets and filters feature to further drill down and find the product that they have in mind with ease.
- 99.9% Uptime- We promise 99.99% uptime for our Expertrec Site Search extension.
- Search analytics- Get insights into what people are searching for in your site. Statistics such as top search queries, zero-result queries are published in your Expertrec control panel.
- Real-time inventory sync- our extension syncs with your Magento store in real-time so that the products in your website sync with the search engine.
- Support- our support team works around the clock to solve your search related queries.