retrieve random images from JCR

Avatar

Avatar

manjushri_wandh

Avatar

manjushri_wandh

manjushri_wandh

15-10-2015

Hi,

My task is to display random images every time user hits the browser.So I want to fetch random images from JCR. My code is as follows

Map<String, String> map = new HashMap<String,String>();
map.put("path", contentPath.toString());
map.put("type", "dam.Asset");
map.put("property", "jcr:content/metadata/dc:format"); 
map.put("property.value", "image/jpeg");

Is it possible to achieve this using Query Builder API?  

Please suggest how I can achieve the same.

Thanks,

Manju

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Ove_Lindström

Avatar

Ove_Lindström

Ove_Lindström

15-10-2015

Hi,

no, the JCR query language does not have any randomizer, but the result set is a collection and you can always use the Java Collections.shuffle(List<?>).

A better solution, if you are going to collect from a named path, is to use the http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/resource/ResourceWrapper.html#get....

/Ove

Answers (0)