Sort index by string

I have a type attribute on my index of books and I am wondering how can I sort the results based on this type. Basically the type will be either NOVEL, COMIC or undefined (not set yet). And I want to prioritise NOVEL books before COMIC on search results. How can I achieve this?

Hello @rizky,

This is doable using an extra field for each record and by tuning one setting parameter.

In your case, you would need to add an extra field, let’s say priority, which would be an integer, to each record. For instance, you could have the following records:

    "title": "It",
    "author": "Stephen King",
    "type": "novel",
    "priority": 1
    "title": "Dying Wish",
    "author": "Dan Slott",
    "type": "comic",
    "priority": 2
    "title": "Harry Potter",
    "author": "J. K. Rowling"

and add a Sort-By attribute on priority (in ascending) on the priority integer field at the top of your index’ Ranking-Formula:


This way, you results will always be ordered first by their priority.

1 Like

Cheers @anthony.seure, that’s like the way to go.