Sort is not working

Hi,

in my application we have sort options like A-Z, Z-A lowest-highest and highest - lowest. we are created one master index(products). For sorting we created replicas with ranking.
For Z-A, we are created one replica like products_name_desc . In dashboard ranking we added title as desc (Custom Ranking Attributes ).
But Z-A sort is not working for info please refer attached

Hey there! Thanks for writing in. I’m working to find an answer and will reply with more info soon, in the meantime I wanted to supply our sorting documentation in case you haven’t seen it just yet.

In the meantime, stand by! :slight_smile:

Hi,
Thanks for your replay.

we are checked the sorting documentation which you shared . we are followed the same but we are not getting proper sorting data.
For example, am searching for rose with sort of descending order on Title filed. But we are getting like below:

[
{
objectID:“3014842”
Title:“Rose Petals”
}
{
objectID:“137424”
Title: “Rose Garden”
},
{
objectID:“82550”
Title"Single Rose Corsage"
}
Expected results should be : Single Rose Corsage" should come first right.

Please guide me on this issue

Hello @shyamsunder.k,

In your screenshot, it’s not obvious what your ranking formula is, and it’s really important to configure properly:

By default, custom ranking is only one criterion among the ranking formula, and not the first one. Which means that textual relevance, or geo distance, for example, will be considered first before your custom attribute. Only records that rank the same for all previous ranking criteria will be sorted by custom attribute.

To make sure results are always sorted by descending alphabetical order of their title, please make sure that desc(Title) is the first criterion in your ranking formula (not just in the custom ranking).

What does in mean in practice? In your dashboard, under the “Ranking” tab for your index, in the “Ranking Formula” section, “Sort by Attribute” should be enabled.

Please let us know if this works for you!

1 Like

Clarification: The only way to achieve alphabetical sorting is to put asc(attribute) in the custom ranking, and custom ranking as the first criterion of the ranking formula:

{
    "custom": [ "asc(attribute)" ],
    "ranking": [ "custom" ]
}

Note: This will completely disregard textual relevance .

For a more in-depth discussion, please refer to this newer post.