Ranking set up for blog: latest posts forst


What is the correct ranking setup for a blog use case, where the default search results should be sorted by date with the latest at the top?

Each record represents a blog post and I have an attribute ‘date’ which is the unix timestamp publish date of a given post.

My understanding is that sort by attribute should not be used on the main / primary index, however I want this to be the default sort for my main index. Should I therefore set a custom ranking of date(desc) even though I want to strictly sort by date?


1 Like


It’s totally fine to use “sort by” attribute on your primary index :ok_hand:
If you move date(desc) all the way up in the ranking formula, you should get what you want.

Thanks Julien, I will change it from a customRanking to a sortBy attribute, although the customRanking did seem to work the same.

I am still a bit confused as to when to use which (and why) since the sorting documentation (https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/) specifically says " you should only add a sort-by attribute to replica indices ." and now I have removed the customRanking I get a red warning in the dashboard “No Custom Ranking”.

Can you provide any further clarification?


Yes, sorry I think I was a bit quick.

Sorting is not recommended for primary index because it usually “degrades” relevancy, surfacing most recent content over most relevant. You’re still free to do it, that’s why I said you can do it but it will really put a big emphasis on recent content.

Using custom ranking, we’ll only put the most recent content first, when 2 (or more) items are considered AS RELEVANT AS each others.

Generally speaking, I’d recommending using custom ranking over sorting for blog content but there are valid reason to use sort by. For example if the content becomes completely irrelevant after X days (event announcement for instance).

If you have an empty query (no search, no filters) then, the order will be the custom ranking, since they will all be considered equals. In this case, the order will be anti-chrono.

You get a red message when there is no custom ranking, because custom ranking really helps finding the most relevant and should always be set. It could be the number of comments or even a simple boolean to surface the “highlighted” posts.

Please let me know if that helps :pray:

Thanks Julien that’s very helpful, this is the key bit of information for me that I don’t think is clear in the documentation:

It’s the default display of results when there are no queries that I want to control, so I’ll change it back to custom ranking.


1 Like

Great, I’ll pass your feedback to the doc team :ok_hand: