Skip to main content
Mar 18, 2025 1:26 PM UTC
Solved

Sorting in Query builder is not working as expected

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.
giuseppebaglio
giuseppebaglioAccepted solution
Level 10
Mar 18, 2025 2:54 PM UTC

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:

 

2 replies

giuseppebaglio
Level 10
Mar 18, 2025 2:46 PM UTC

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 

Translate
giuseppebaglio
giuseppebaglioAccepted solution
Level 10
Mar 18, 2025 2:54 PM UTC

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:

 

Translate