22 May 2018

How can I randomize my results?

One of Algolia’s primary design goals is to always yield the most relevant results, with a predictable ranking formula that can be easily understood and fine tuned. Randomizing results would rather defeat that purpose…

This is why there is no built-in way to randomize Algolia’s results. There are, however, a few possible solutions:

  1. Periodically shuffling results. In this solution, you add an attribute with a random integer value to all your objects. You can then use this attribute as part of the custom ranking in your ranking formula. The results will still be predictable, in the sense that all users will get identical results for the same query. But you may periodically change the random value and re-index the objects, thus changing the results order. Use this if you want to implement a kind of “random daily selection”, for example.
  2. Randomize results on the client side. In this case, you shuffle results after they are returned by Algolia. When doing so, you may want to retrieve additional ranking information (getRankingInfo=true) to make sure you don’t break the relevance. In particular, you should only swap group of objects ranking identically.