Query Build API - Results in random order | Community
Skip to main content
Level 5
July 31, 2020
Solved

Query Build API - Results in random order

  • July 31, 2020
  • 3 replies
  • 1370 views

Hello Community - Currently I am using query Builder API to fetch the results from JCR.

 

One query using sort by on lastModified date  and other requirement is to return the "results in random order (I don't mention any orderby here)" when I query JCR, both the options gives me the results in same order. Could you please tell me how to fetch the results by lastModified date.

 

Below is the query that I am using for OrderBy

path=/content/xx/en/yy/test
1_property=sling:resourceType
1_property.value=yycomponents/page/abc
1_property.operation=like
orderby=@jcr:content/cq:lastModified
orderby.sort=desc

p.limit=50

 

Thanks in advance.

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 ChitraMadan

Hi @v1101 ,

 

The Only property that you need to change in your query is the orderby as highlighted below:

 

path=/content/xx/en/yy/test
1_property=sling:resourceType
1_property.value=yycomponents/page/abc
1_property.operation=like
orderby=@cq:lastModified
orderby.sort=desc

p.limit=50

 

The reason fo this is, the query will return the paths till jcr:content and then the query was checking cq:lastModified in jcr:content/jcr:content/cq:lastModified and hence it was not working.

With above change, it should work fine.

Hope this helps!!

3 replies

vanegi
Adobe Employee
Adobe Employee
July 31, 2020

You can try something like:

 

fulltext=we-retail
group.p.or=true
group.1_p.and=true
group.1_path=/content
group.1_type=cq:Page
group.1_relativedaterange.property=jcr:content/cq:lastModified
group.1_relativedaterange.lowerBound=-1M

 

OR 

 

1
2
3
type=cq:Page
orderby=@jcr:content/cq:lastModified
orderby.sort=desc



Please check https://helpx.adobe.com/in/experience-manager/6-3/sites/developing/using/querybuilder-api.html for more details. Thanks!!

v1101Author
Level 5
August 6, 2020
Thanks everyone, the sort by last modified worked perfectly. My another question was how to query to get results in random order. For every query of JCR, the ordey by should be random. Like in SQL where there is order by rand(). Could someone help with this.
ChitraMadan
Community Advisor
ChitraMadanCommunity AdvisorAccepted solution
Community Advisor
July 31, 2020

Hi @v1101 ,

 

The Only property that you need to change in your query is the orderby as highlighted below:

 

path=/content/xx/en/yy/test
1_property=sling:resourceType
1_property.value=yycomponents/page/abc
1_property.operation=like
orderby=@cq:lastModified
orderby.sort=desc

p.limit=50

 

The reason fo this is, the query will return the paths till jcr:content and then the query was checking cq:lastModified in jcr:content/jcr:content/cq:lastModified and hence it was not working.

With above change, it should work fine.

Hope this helps!!

arunpatidar
Community Advisor
Community Advisor
August 3, 2020

Try to create your query in below format.

 

path=/content/we-retail type=cq:Page 1_property=jcr:content/sling:resourceType 1_property.value=weretail/components/structure/page 1_property.operation=like orderby=@jcr:content/cq:lastModified orderby.sort=desc

 

Arun Patidar