How to use order by with multiple isdescendantnode
Asked Answered
E

1

7

I am attempting to grab multiple nodes of the same type from different areas in the jcr and order them by a date.

SELECT * FROM [social:asiResource] 
WHERE [sling:resourceType] = 'social/qna/components/hbs/topic' AND 
[isFeatured_b] = true AND 
NOT CONTAINS([cq:tags],'administrative:blacklist') AND 
(ISDESCENDANTNODE([/path/to/content]) OR 
ISDESCENDANTNODE([/path/to/content]))
ORDER BY [cq:lastModified] DESC

This will return me the correct set of results but not in the correct order. In fact altering DESC to ASC does not alter the results in any way.

My solution currently is to do multiple queries and perform a union which allows ORDER BY to function like it should.

SELECT * FROM [social:asiResource] 
WHERE [sling:resourceType] = 'social/qna/components/hbs/topic' AND 
[isFeatured_b] = true AND 
NOT CONTAINS([cq:tags],'administrative:blacklist') AND 
ISDESCENDANTNODE([/path/to/content]) 
UNION 
SELECT * FROM [social:asiResource] WHERE 
[sling:resourceType] = 'social/qna/components/hbs/topic' AND 
[isFeatured_b] = true AND 
NOT CONTAINS([cq:tags],'administrative:blacklist') AND 
ISDESCENDANTNODE([/path/to/content])
ORDER BY [cq:lastModified] DESC

Unfortunately I have around 30 nodes that I am searching through making the latter query unusable. Is there a way to use ORDER BY without using a UNION?

Eadwina answered 15/3, 2017 at 21:38 Comment(0)
E
0

The initial query is now working. It seems like there was some other factors leading to the ORDER BY not giving valid results.

To clarify you can ORDER BY when using multiple ISDESCENDANTNODE's.

Eadwina answered 16/3, 2017 at 18:59 Comment(1)
Also NOT CONTAINS seems to slow down the query quite a bit.Eadwina

© 2022 - 2024 — McMap. All rights reserved.