Algolia Integration with Magento 2

Algolia Integration with Magento 2 for Real-time Search

Rahul Anand

Rahul Anand

Sr. Technical Lead

Published Aug 25 2019

In eCommerce, providing correct, fast, and user-friendly Search is very important. The ease of finding the desired product and relevance of search results has a direct impact on the revenue. Since 43% of all eCommerce traffic is generated from Google organic search, it isn’t yet time to slow down your search engine optimization (SEO) efforts.

In the last few years, we’ve seen a drastic change in consumers’ product search habits; marketplaces have become a direct and primary destination for any product purchased. 1 of every 4 sales related to a brand-specific search takes place in an online marketplace.

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.

Magento 2 Search Capabilities:

  • Magento 2 provides a Full-Text search functionality by default, wherein the customer can find the product that is an exact match to the search term. For example, a search for “blue shirt” will only result in products that have a “blue shirt”.
  • Magento 2 does not provide the option to set a comparable method for MySQL engine.
  • As an open-source tool, Magento 2 allows MySQL as a search engine only. The Commerce edition offers the merchants an option to work with Elasticsearch, MySQL, and Solr.
  • You can find search settings at Configuration > Catalog > Catalog > Search Engine Optimization.

There are search mechanisms like Algolia and Elastic Search that allows faster and more customized, multi-faceted searches when compared to Magento search. In the next section, we will go through the steps required to install and configure Algolia search for your Magento 2 eCommerce website.

About Algolia

Algolia is a U.S.-based company that offers a web search product through Software-as-a-Service (SaaS) model. Using Algolia, developers can create a personalized site search that provides fast and reliable search experience. Algolia provides flexible APIs and UI toolkits that allow developers with the resources necessary to build the experience that is best suited for an eCommerce search. Algolia works on Distributed Search Network (DSN) and has 70+ data centers across 16 regions.

Algolia allows the customers to spend less time thinking about how to search and focus more on what they want to purchase. The users can search the entire catalog using this Algolia search with quick results as they type. Since these results are updated in real-time, it helps in improving the search and increases sales rate. Integrating Algolia is very simple and can be done in a few minutes with few configurations.

Understanding the Salient Features of Algolia

  • Language Support – It works with all languages and supports both left-to-right and right-to-left scripts, without any additional work.
  • Fast Results – Real-time search speeds-up the results for your customers via a distributed search network.
  • Typography Tolerance – Customers make typos. Algolia understands misspelled words and shows the search results that the customer was meaning to type.
  • Instant Faceting – You can build an intuitive, faceted experience based on the customers’ previously selected facets and query. The instant, relevant results make for a great feature.
  • Analytics – Analyze your customers’ preferred choices with a graphical dashboard that provides information on ‘what your customers are searching’ and ‘how they are searching’.
  • Catalog Auto-Sync – Algolia provides a cron job that syncs search indexes with your updated catalog information like name, description, price, quantity, etc., in real-time.
Algolia Installation and Configuration

Before using Algolia with Magento, the user must create an Algolia account. Algolia can be installed from Magento Composer using the command mentioned below -

> composer require algolia/algoliasearch-magento-2

After installing Algolia, update the Application ID key, Search-only API key, and Admin API key in Magento (Navigate to Stores > Configuration > Algolia Search in Magento Admin for Algolia related configuration).

Magento Admin configuration for Algolia

How Algolia works

After Algolia is installed and configured, define the attributes (facets) that will be searchable on the website.

Algolia Attributes/Facets

After completing the facet configuration, clean the cache from Magento admin.

Cleaning Magento Cache

Upload Magento data on Algolia servers and index them to become searchable. The indexing queue processes updates to products, categories, pages, and any other data by synchronizing updates to Algolia servers.

To run the queue managers, asynchronously configure Algolia queue and schedule crons as mentioned below:

1) To enable the indexing queue, navigate to System > Configuration > Algolia Search > Indexing Queue/Cron in Magento administration.

Indexing the Queue

2) For indexing of new products, set the following indexing commands set in the cron:

$ php bin/magento indexer:reindex algolia_products

The same command can be used for all other Algolia indices:

  • algolia_products - Reindexes all products
  • algolia_categories - Reindexes all categories
  • algolia_pages - Reindexes all CMS pages
  • algolia_suggestions - Reindexes all search query suggestions
  • algolia_additional_sections - Reindexes all additional sections
  • algolia_queue_runner - Process jobs in the indexing queue
  • algolia_delete_products - Removes inactive products from Algolia indices

3) Schedule a cron to send catalog updates to Algolia at the desired frequency (generally scheduled every 5 minutes)

*/5  * * * php bin/magento indexer:reindex algolia_queue_runner

This crontab will run every five minutes, running the number of operations set in the configuration (10 by default).

Once the above configurations are complete, the products, attributes, categories, and suggestions that are configured on Algolia can be searched in real-time.

Product Search on Algolia

Search Results on Algolia

Algolia is easy to configure in Magento for any eCommerce website. Magento and Algolia together provide a powerful suite for better customer experience through a fast and reliable search. It will make a great way to provide the fastest and most relevant search experience to your customers.