Orderby sequence in Query builder | Community
Skip to main content
manikanthar1295
Level 5
Dec 14, 2022 4:25 PM UTC
Solved

Orderby sequence in Query builder

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.
Siva_Sogalapalli
Siva_SogalapalliAccepted solution
New Participant
Dec 16, 2022 12:40 PM UTC

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

 

 

4 replies

Siva_Sogalapalli
New Participant
Dec 14, 2022 9:36 PM UTC

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

Translate
manikanthar1295
Level 5
Dec 15, 2022 4:58 PM UTC

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.

Translate
Siva_Sogalapalli
Siva_SogalapalliAccepted solution
New Participant
Dec 16, 2022 12:40 PM UTC

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

 

 

Translate
Saravanan_Dharmaraj
New Participant
Dec 14, 2022 5:50 PM UTC

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. 

Translate