Skip to content

Instantly share code, notes, and snippets.

@QuincyLarson
Created May 2, 2014 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuincyLarson/6d6f45e28061b023c1a4 to your computer and use it in GitHub Desktop.
Save QuincyLarson/6d6f45e28061b023c1a4 to your computer and use it in GitHub Desktop.
function randomCallback(success, content) {
if (success) {
for (var i = 0; i < content.hits.length; ++i) {
window.location.assign("/?id=" + content.hits[0].id);
}
}
}
$('#random_button').click(function(e) {
var index = client.initIndex('#{Clip.index_name}')
var random_page = (Math.floor(Math.random() * 999) + 1);
index.search('', randomCallback, { "hitsPerPage": 1, "page": random_page});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment