Adding SKU Numbers to a Smart Search index
Kentico has a very powerful search built on Lucene.Net, one of the most scalable and configurable search platforms available. Developers can easily configure any page type field to be searchable, as well as customize the syntax and parameters that users can filter on. Often pages have an associated SKU and users also need to search the product fields. In this blog I will show you how to add the SKU Number field to the index so that users can also search for these values.
Overview
By default, Kentico includes several fields from the SKU record as part of the search index. When a user creates a new index, they select the desired page type (or other data type) and build a new index. Depending on which page type fields have been configured for indexing, Kentico will crawl through the data and create the appropriate index for the data. As part of that index, Kentico will also include a number of “standard” fields from associated SKU and document records. This allows you to search values not necessarily only on the page type, but also on the document and SKU data.
While some sites can provide adequate searching using only these “standard” fields, in past projects I have often found the need to add a few additional fields. The SKU Number value is a common one as many ecommerce stores use these values to identify their products and users will often search by them. Luckily, adding this field to the index is a simple task!
Review the Page Type
In the provided exmaple, I am using the DG sample site. You can see that we have a simple brewer page type with a few fields configured for searching.
In my example, the user needs to search for the product by the SKU Number. This field is not included by default, so it has to be added.
Here are the results when I search by this value. Unfortunately, I won’t be buying the exmaple brewer because I won’t be able to find it when I search the site.
Updating the SKU Class
Adding the SKU Number to the index is a very simple task. All we need to do is to update the SKU class so that the field is part of the Content data. Once we have that in place, our users will be able to find their product by the SKU Number value and hopefully drive more sales.
In the E-commerce Module, click on Classes and then SKU.
Under Search, check the Searchable checkbox for the SKU Number field.
After that, I will need to rebuild the index so the new data is included.
Testing
Now that I have our index rebuilt, let’s test it to make sure we get the results we expect.
Pretty awesome, right? You can easily add any field you need to your indexes by modifying the appropriate class that contains the data. Some system classes are not modifiable, but, the SKU class is one you can customize. As the most integral part to an ecommerce site, the SKU class can easily be updated to include whatever field you need to get the results for which your users are looking.
The Fine Print
While it is possible to modify some of the system classes, only do so if you know exactly what you are changing! Modifying the system tables can affect other areas of the search functionality so be sure you read the documentation to understand exactly how the search functions.
You can view the Smart Search documentation here.
Hopefully this blog helps you to get your search working great and provides your users with the results they need. Good luck!
This blog is intended to demonstrate one of many ways to accomplish this task. Always consult the Kentico Documentation for best practices and additional examples.