I want to write a query in AEM query builder to fetch the cq:Pages under a path based on some tags in descending order based on multiple value.
I am able to write the query but the sorting part is little tricky. We have to sort the result primarily on publishedDate. if it is not there then use the lastmodified date.
Only the sorting part I'm struggling. Please help
Views
Replies
Total Likes
Hi @Linu
Please find the below query for your requirement.
type=cq:page
path=/content/path
orderby=@jcr:content/cq:lastReplicated
orderby.sort=desc
p.limit=-1
Hope this helps!
Views
Replies
Total Likes
Thanks for the answer, but this is not what I'm looking for. This is purely based on 1 property the sorting is happening, I want to use something like if there is publication date property is available then use it otherwise use the last modified date. Both are date properties.
Views
Replies
Total Likes
Please try orderby
Allows the results to be sorted. If ordering by multiple properties is required, this predicate must be added multiple times using the number prefix, such as 1_orderby=first
, 2_oderby=second
.
orderby
Either JCR property name indicated by a leading @, for example, @jcr:lastModified
or @jcr:content/jcr:title
, or another predicate in the query, for example, 2_property
, on which to sort.
sort
Sort direction, either " desc
" for descending or " asc
" for ascending (default).
case
If set to ignore
, it makes sorting case insensitive, meaning “a” comes before “B”; if empty or left out, sorting is case-sensitive, meaning “B” comes before “a”
If OOTB doesn't give required result, create a custom Query Predicate. A sample code of similar usecase is available on this thread https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sortby-two-values-at-a-tim...
Hi @Linu
Please try:
path=/content/your-path
type=cq:Page
property=jcr:content/cq:tags
property.value=tag1,tag2
orderby=@jcr:content/cq:lastReplicated
orderby.sort=desc
orderby.secondary=@jcr:content/cq:lastModified
orderby.secondary.sort=desc
Already tried this, but not giving the desired output.
Views
Replies
Total Likes
Hi @Linu
What problem you are facing using the above?
Views
Replies
Total Likes