I have the following code
var vec:ViewEntryCollection = database.getView("view").getAllEntriesByKey("Mykey",true)
how can I make "vec" in random order using SSJS (or java) so that I get a new order every time?
I have the following code
var vec:ViewEntryCollection = database.getView("view").getAllEntriesByKey("Mykey",true)
how can I make "vec" in random order using SSJS (or java) so that I get a new order every time?
How about having a secondary sort column on the view with a formula of @Unique
. Would need to refresh the view each time and performance may not be great if the view is big.
Considered the average collection size I would loop through the collection and add each item to a Java list or a JavaScript array.
If you go Java you can use Collections.shuffle.
If you go JavaScript you can use well established functions/algorithms
For better performance, do NOT keep collection entries in memory. First, make list/array of UNIDs from your view. That will be the slowest part. Then pick any random number and pick desired number of UNIDs from the list/array. Call getDocumentByUnid or initialize (say 10) datasources.