A step by step guide for using Azure search for your eCommerce store

Do you have an ever growing product catalog wherein the products need be searched as free text, filtered, sorted faster so that the customers visiting the site get a seamless and easy search experience?

Well, when customers shop online, they are in an urge to zero down on the product that they need as quickly as possible.

Time is valuable!

If they do not find the right product quickly enough they do not hesitate to move over the next best eCommerce store, as it is that easy. Making the buying process simple, holding onto the visitors and converting them into potential customers is always a challenge.

In the same way, one of the customers came to us for developing eCommerce web application withÂ scalable eCommerce search solution, this is how we solved their problem.

Here is a step by step process we followed to solve their problem:

Stuck to RDBMS!

Initial thoughts – we use relational database to save the product data and build queries to filter the data. But, with relational database writing dynamic queries and getting optimum performance from the queries is difficult and time consuming. Also, with product catalog increasing regularly, foreseeing the ever growing list of different properties being added to each product type was always going to be a herculean task.

Is NOSql the right alternative for ever growing product catalog?

Yes for sure. With no schema restriction NOSql alternative such as MongoDb seems to be the right solution. But, the performance efficiency of the filtered result depends on how the query is formed and number of factors such as shards, replica sets, data nodes are taken into consideration to deliver performance. As the scalability requirements go up we need to scale the database as per the above parameters. Also, how do I get free text search implemented, usually some search platform based on Lucene search is ideal.

Is there an easier search solution based on Lucene?

Yes there very good alternative search solution i.e. ElasticSearch which is based on Lucene. ElasticSearch provides distributed, multitenant capable full-text search engine which can take schema-free JSON documents.

But similar questions does it scale on its own?

No. Indices have to be created and divided into shards with each shard having one or more replicas. Infrastructure has to be managed.

Solution

Is there something available online that I can just use without worrying about infrastructure?

Yes indeed – Azure Search. Wiki Gyan – Azure Search is a cloud search-as-a-service solution that delegates server and infrastructure management to Microsoft, leaving you with a ready-to-use service that you can populate with your data and then use to add search to your web or mobile application.

This exactly fits my requirement where we can have the product catalog uploaded to Azure Search. Also, more importantly the eCommerce web application we created was in ASP.NET MVC deployed in Azure Web Apps that does mean integration and management from Azure Portal becomes easier

How do I get started?

Provision Search service in the Azure Portal like any other service. Choosing the right region for data center was more important primarily taken into consideration the proximity to the eCommerce Web App provisioned, so assigned the same region.

What next?

Create index for data i.e. product catalog with all the possible fields. What is index? Azure documentation – An index is a persistent store of documents and other constructs used by an Azure Search service. A document is a single unit searchable data in your index i.e. JSON. As in database or JSON there are properties/fields wherein the field datatypes should be as per the specifications for Azure Search. Refer this URL for more details on Index – https://azure.microsoft.com/en-us/documentation/articles/search-what-is-an-index/

There are alternative techniques to create an index, we used Azure Search .NET SDK to create an index. Steps are pretty simple

1. Download the Azure Search .NET SDK NuGet packageby using “Manage NuGet Packages” in Visual Studio. Just search for the package name Microsoft.Azure.Search on NuGet.org

2. Initialize object for SearchServiceClient providing the right search service name given in the azure portal and apikey

Note : filter uses OData syntax, so say for example user wants to search for any hotel with added filter for City name as “Mumbai” the call would be as follows

SearchData(indexClient, searchText: "*", filter: "city eq 'Mumbai'");

As in the above example, we built a comprehensive library to accommodate all the possible filters and corresponding queries for the same in our application

Challenges

Developing any application cannot be accomplished without any challenges.

1. Re-Populating/Updating data regularly

Writing code and repopulating the data becomes tedious every time the data changes or gets added. Syncing data and keeping data up to date was a challenge. With azure, we can integrate directly with some common data sources, removing the need to write code to index your data. To set up this up, you can call the Azure Search API to create and manage indexers and data sources.

Setting up automatic indexing is typically a four step process:

Identify the data source that contains the data that needs to be indexed. Keep in mind that Azure Search may not support all of the data types present in your data source. See Supported data types (Azure Search) for the list.

As mentioned in the above step, we created a view which would return a list of products with all possible properties for that product. We setup an indexer which runs every 12 hours to make sure the index data is up to date

2. Query Performance

When multiple performance tests were run, we found that the query performance especially response time was bad as we increased the load. Again, Azure documentation makes sure that the search limits are defined which defines 15 queries per second for S1 instance per replica.

Search Explorer – Check the queries against the indexes for refining it, before it can be used in the application

Very successful companies realize how important search is to engage their users and drive Sales. They continuously invest in search technology to optimize both their user experience and promote their products at the same time.

But what about you? Perhaps you think that as a small, medium, or even large online merchant, you have neither the funds nor people to maintain an Amazon-like search engine on your web site? Implementing Azure Search can help to build a scalable search solution quickly, also allowing to scale search independently as per search needs, at the same time improve performance of the site.

With this addition, you can improve on your site search, engage your visitors, and increase conversion rates on your site.

About Tech Vedika

We are an Agile Software Development company focused on helping mid-size businesses reach their full potential by being their scalability and technology partners. We are passionate about things we do, striving for simple, elegant technology solutions in response to complex tasks.