Random sort order
Although it may make sense to have a random order in the ranking formula, it is incompatible with how the engine was built. Focusing on speed + relevance, the Algolia engine made some trade-offs as it predicts a lot of information when indexing, which makes randomization impossible with every request. In addition, it breaks any pagination.
However, you can shuffle the results after receiving them, which allows you to have the correct pagination.
Using the shuffle method of this question How to shuffle an array? :
function shuffle (o){ for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; }
With JavaScript client :
index.search('something', function searchDone(err, content) { content.hits = shuffle(content.hits);
With javascript helper :
helper.on('result', function (data){ data.hits = shuffle(data.hits);
Request for a nonexistent attribute
The only way to do this with Algolia is to press a value that you consider null (for example, a string of null or -1 for positive integers).
source share