Sorting in Query builder is not working as expected | Community
Skip to main content
March 18, 2025
Solved

Sorting in Query builder is not working as expected

  • March 18, 2025
  • 1 reply
  • 469 views

I have query builder parameter as

path=/content/sample/en type=cq:Page orderby=@jcr:content/jcr:title orderby.sort=asc p.limit=-1


Now I have two Pages as
/content/sample/en/sample-page  (jcr:title -> Sample Page)
/content/sample/en/1-page  (jcr:title -> 1 Page)

/content/sample/en/3  (jcr:title -> 3)

/content/sample/en/3-page  (jcr:title -> 3 Page)

Ideally I should get numeric at the top but I am getting order as
/content/sample/en/3  (jcr:title -> 3)

/content/sample/en/3-page  (jcr:title -> 3 Page)

/content/sample/en/sample-page  (jcr:title -> Sample Page)

/content/sample/en/1-page  (jcr:title -> 1 Page)

This is incorrect am I doing something wrong here need guidance from the community

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 giuseppebaglio

I've just noticed the same ordering as you with a simple space after jcr:title: not working vs working 

You can see the space char highlighted in blu and pages are sorted by creation date:

 

1 reply

giuseppebaglio
Level 10
March 18, 2025

hi @rohanra6

I've created pages with the same structure as yours:

and query results are exactly as expected:

You can see on the left a slightly changed query hitting on cq:PaceContent as a reference for comparison (non-suggested though because OOTB there is no index defined already).

The results are as expected so I'm guessing that your sample-page has a number at the beginning of the jcr:title property? 

If not please have a look at General Debugging Recommendations so you can obtain more clarity about the query with Explain Query 

giuseppebaglio
giuseppebaglioAccepted solution
Level 10
March 18, 2025

I've just noticed the same ordering as you with a simple space after jcr:title: not working vs working 

You can see the space char highlighted in blu and pages are sorted by creation date: