Expand my Community achievements bar.

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

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

Avatar

Level 2

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

Screen Shot 2018-06-19 at 11.09.09 PM.png

Thanks

Arun



Arun Patidar

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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.

Screen Shot 2018-06-19 at 11.09.09 PM.png

Thanks

Arun



Arun Patidar

Avatar

Level 2

Thanks Arun. It helped.

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