Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

retrieve random images from JCR

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

1 Reply

Avatar

Correct answer by
Level 6

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