Managing Data by Adding Custom Ranking to Our Search Results

Learn how to manage results' ranking based on certain attributes using the API or dashboard. Additionally, interact with the sample code to practice customising the ranking before sending the dataset using Aloglia's API.

Overview

In the previous lesson, we talked about how we manage the dataset configs and customise them based on the requirement using the API or dashboard.

In this lesson, we will be talking about how we can manage our data and control the ranking (sorting) of that data by using the customRanking parameter.

The customRanking parameter specifies the custom ranking criteria. This parameter can be used inside the setSettings method in the API or directly in the dashboard.

Using API

In order for Algolia to customise the ranking of the search based on our requirement, we need to set it using the setSettings method, which accepts an array of strings. Each string must follow this syntax: asc(${attribute}) or decs(${attribute}), which will sort the ranking of hits by increasing or decreasing the value of the attribute passed.

index.setSettings({
  customRanking: [
    'desc(price)',
  ]
});

Get hands-on with 1200+ tech skills courses.