Open navigation

Sort Order Options

This content contains older information from our previous Javascript library. Please visit the link if you have implemented Klevu with the latest template JS.

If you are using Klevu hosted templates to display search results to your customers, we automatically make the following sort order options available:

  • Relevance [rel]
  • Price: Low to High [lth]
  • Price: High to Low [htl]

We also support the following additional sort order options, should you wish to add them:

  • Name: A-Z [NAME_ASC]
  • Name: Z-A [NAME_DESC]
  • Rating: Ascending [RATING_ASC]
  • Rating: Descending [RATING_DESC]
  • Newness: Old to New [NEW_ARRIVAL_ASC]
  • Newness: New to Old [NEW_ARRIVAL_DESC]

Currently these are the only sort options available. Any other sort option specified in a search request to Klevu will use the default sorting method: RELEVANCE.

Relevance sorting uses a combination of Klevu A.I. and your own merchandising configuration to determine the order of the results. For Price and Name the results are ordered according to their sale price and alphabetical name respectively. Rating can be used to sort your results by their average review score.

You can use Newness to sort by the latest arrivals in your catalogue, but this requires some additional considerations which are detailed below in the section: “Sorting by Newest Arrivals”.

Integrating a new Sort Order Option

With a Klevu template integration there will already be some sort orders available in your HTML code for Relevance and Price. Your frontend developer can find them by searching in your theme for a dropdown with the name: `kuSortby`.

For Shopify App users you would modify the Web Page “Search Results Page” content. For BigCommerce App users, modify your `search.html` template. For Magento extension users, modify the `search/index.phtml` file.

Please follow the same code format and structure of the `<option/>` values already available in your own implementation, and add the additional options you require. An example of what this might look like is as follows:

<select name="kuSortby">
<option value="rel">Relevance</option>
<option value="NEW_ARRIVAL_DESC">Newest Arrivals</option>
<option value="RATING_DESC">Avg. Customer Review</option>
<option value="lth">Lowest Price</option>
<option value="NAME_ASC">Alphabetical</option>
</select>

Sorting by Newest Arrivals

When sorting by Newness, Klevu needs an attribute in your product data which indicates its age. By default Klevu uses the `id` of your item, however depending on the format of your ID you may wish to exchange this for a different field, due to the sorting logic highlighted below.

All attributes in Klevu, apart from sale price, are stored as non-numeric text values. In order to see the newness sorting you expect, the attribute used must be provided in a sortable format. The easiest way to explain this is with an example.

Let’s say you have three products with the following IDs:

  • Item A has ID: 100
  • Item B has ID: 300
  • Item C has ID: 1000

The order expected in the search results would be A-B-C. However, `id` is a text value so it will be ordered in an alphabetical manner, A-C-B, due to “1” coming before “3” in the alphabet. Therefore it is better to use a date format attribute for determining the age of your products:

  • YYYY-MM-DD, eg. 1999-12-31
  • or YYYY-MM-DDTHH:MM:SS, eg. 1999-12-31T23:59:59

For Shopify, BigCommerce and Magento customers, the framework-specific sections below detail your options for making this attribute of your product data available to Klevu. Once you have decided which attribute you would like to use for newness sorting, please contact Klevu support (support@klevu.com) with a request:

“Please map `{your chosen attribute}` to newness, for my store with JS API Key {klevu-123456}”.

Klevu Support will then perform the relevant tasks and inform you once it is ready, after which you can complete the integration step detailed above: “Integrating a new Sort Order Option”.

Shopify App customers 
For customers using our Shopify App, Klevu includes an attribute `created_at` which is based on the creation date of your product with the format: `1999-12-31T23:59:59`. Alternatively, if you wish to base the newness sorting on a different data point or a specialised date format, you can create and populate a Tag or Metafield with your custom value.

BigCommerce App customers
For customers using our BigCommerce App, Klevu indexes an attribute `klevu_creation_date` based on the creation date of your product with the format: `1999-12-31`. Alternatively, if you wish to base the newness sorting on a different data point or a specialised date format, you can create and populate a Custom Field or Metafield with your custom value.

Magento Extension customers
For customers using our Magento Extension, if you wish to use the Magento Product creation date, please include `created_at` in your “Other Attributes to use in Search” which will be in the format `1999-12-31`. Alternatively, if you wish to base the newness sorting on a different data point or a specialised date format, you can create and populate another attribute and include that in the same manner as the above link.

All other customers
For all other customers, please make an appropriate attribute available in your feed data or indexing API calls with the format: '2021-05-14T02:42:13Z'.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.