retrieve random images from JCR | Community
Skip to main content
Level 2
October 16, 2015
Solved

retrieve random images from JCR

  • October 16, 2015
  • 1 reply
  • 1694 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ove_Lindström

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#getChildren%28%29.

/Ove

1 reply

Ove_LindströmAccepted solution
Level 6
October 16, 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#getChildren%28%29.

/Ove