Can QueryBuilder.createQuery can have params as sling:resourceType and orderBy.sort property together? | Community
Skip to main content
Level 2
June 19, 2018
Solved

Can QueryBuilder.createQuery can have params as sling:resourceType and orderBy.sort property together?

  • June 19, 2018
  • 3 replies
  • 2032 views

Map<String, String> params = new HashMap<>();

params.put(KEY_PATH, path);

params.put("type", "cq:Page");

params.put("orderby", "jcr:content/@cq:lastModified");

params.put("orderby.sort", "desc");

params.put("1_property", "jcr:content/sling:resourceType");

params.put("1_property.value","cq/experience-fragments/components/xfpage");

params.put("p.offset", "0");

params.put("p.limit", "-1");

params.put("p.guessTotal", "1");

Query query = queryBuilder.createQuery(PredicateGroup.create(params), session);

Here I am getting all the pages of type "cq/experience-fragments/components/xfpage" but I am losing the orderby property. Am I doing wrong something here?

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 arunpatidar

You may need to change orderby with below:

params.put("orderby", "@jcr:content/cq:lastModified");

I ran the same query with above changes and I am able to get results in descending order.

Thanks

Arun

3 replies

Lokesh_Shivalingaiah
Level 10
June 19, 2018

Yes.. you can have

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
June 19, 2018

You may need to change orderby with below:

params.put("orderby", "@jcr:content/cq:lastModified");

I ran the same query with above changes and I am able to get results in descending order.

Thanks

Arun

Arun Patidar
manasipAuthor
Level 2
June 20, 2018

Thanks Arun. It helped.

params.put("orderby", "@jcr:content/cq:lastModified");  is the correct way.