Orderby sequence in Query builder | Community
Skip to main content
manikanthar1295
New Participant
December 14, 2022
Solved

Orderby sequence in Query builder

  • December 14, 2022
  • 2 replies
  • 1756 views

Hi Team,

 

I need to sort page by custom property called  sequence.

I have created Custom property called sequence for page.

So that each page have custom property like page1 will have sequence number is 1

page 2 will have sequence number 2

for some page there won't be sequence number now i need to sort in such a way that the pages with have sequence number in  ascending order  and if page won't have sequence number it should come last.

Can some one help me with  predicate for sort in above manner. 

 

 

 

 

 

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 Siva_Sogalapalli

Hi @manikanthar1295 

 

try below and see if that works for you. It gives only if the property exists. 

 

type=cq:Page
path=/content/we-retail/us/en/contact

property=@jcr:content/sequence
property.operation=exists
orderby=@jcr:content/sequence
orderby.sort=asc 

p.offset=3
p.limit=3

 

----- AND below for other pages where the property doesn't exist.

 

type=cq:Page
path=/content/we-retail/us/en/contact

property=@jcr:content/sequence
property.operation=not

p.offset=3
p.limit=3

 

 

2 replies

Siva_Sogalapalli
New Participant
December 14, 2022

Hi @manikanthar1295 

I don't think you can achieve both with single query. so You can try with two different queries and store in in the list & later merger them.

 

Sample Query:

path=/content/abc
type= cq:Page
orderby=@jcr:content/jcr:title
orderby.sort=ascp.limit=-1

manikanthar1295
New Participant
December 15, 2022

HI Siva,

 

Thanks for your quick reply.

 

My requirement is we have 10 pages among 10 pages 5 pages have sequence number and five pages not have sequence number.

 

when i use Query builder like below 

type=cq:Page
path=/content/we-retail/us/en/contact
orderby=@jcr:content/sequence
orderby.sort=asc  its giving without sequence first and then with sequence number.

 

 

 

 

 

 

I am using pagination so each time i need 3 records so i have used  p.offset=3
p.limit=3

 

query builder will be 

 

type=cq:Page
path=/content/we-retail/us/en/contact
orderby=@jcr:content/sequence
orderby.sort=asc 

p.offset=3
p.limit=3

 

It will give 3 pages  without sequence  first 

 

I need to get with sequence first how i can achive these.

Siva_Sogalapalli
Siva_SogalapalliAccepted solution
New Participant
December 16, 2022

Hi @manikanthar1295 

 

try below and see if that works for you. It gives only if the property exists. 

 

type=cq:Page
path=/content/we-retail/us/en/contact

property=@jcr:content/sequence
property.operation=exists
orderby=@jcr:content/sequence
orderby.sort=asc 

p.offset=3
p.limit=3

 

----- AND below for other pages where the property doesn't exist.

 

type=cq:Page
path=/content/we-retail/us/en/contact

property=@jcr:content/sequence
property.operation=not

p.offset=3
p.limit=3

 

 

Saravanan_Dharmaraj
New Participant
December 14, 2022

I would suggest to do by fetching all the pages and bucket the one with sequence property in separate list and do sort the list by sequence and other list for pages don't have sequence property and merge the list.