In this article, we will review 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 Magento 2.
How To Make a Magento 2 Create Custom Search Engine
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 Magento 2 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 Magento 2, 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
Using a Magento 2 Custom Search Form Plugin
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 users 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 on 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.
How to add a Magento 2 Custom Search Results Page
In a nutshell, a store always has several tools that users employ to look for the products they want. And the search is the main one! Magento 2 offers a list of features for flexible search tuning so that your customers will be able to find and purchase exactly the products they need. Along with the actual search engine, the search results page where the results are displayed is equally important.
Search is executed by text attributes, which are configured for Use in Search. The results’ relevance is counted taking into account the search weight parameter, which is located at Stores > Attributes > Product, as well as the Use in Search setting.
In Magento 2, the search autocomplete feature is named Suggested Terms. Thanks to this option, the users are offered the existing and non-empty (with at least one result available) search terms. Thus, Magento 2 changes a search query or finishing it on the fly while a visitor remains satisfied with the shopping process
The whole search is sometimes not satisfactory and customizing it can be quite difficult. Unless you are very comfortable editing code, changing the appearance of the search results page can also be a challenging task.
Using a Magento 2 Custom Search Results Plugin
On Magento 2, all that you need to do is install the ExpertRec site search extension from the marketplace. This will automatically replace your default search and add a search bar that has facets inbuilt. You can do further customization in the Expertrec Dashboard that comes along with the plugin.
The dashboard allows you to customize the search ranking and the UI of the search bar. Additionally, you can change the appearance of the search results page as well. This can be done quickly, without any coding.
Magento 2 Custom Search Service
What if the plugin way is not working for you? Well, there is still a way to add a search to your Magento store! This comes will the same features as the above methods, including a custom search results page.
You can easily create a magento 2 search engine using expertrec for as low as 9 USD per month. Here are the steps-
- Go to https://cse.expertrec.com?platform=cse
- Enter your magento 2 wesbite URL
- Enter you magento 2 sitemap URL.
- Wait for crawl to complete.
- Add the search box code to your magento 2 website.
- Upgrade to a paid plan and take live.