Querying for Nodes, only first level | Community
Skip to main content
October 16, 2015
Solved

Querying for Nodes, only first level

  • October 16, 2015
  • 2 replies
  • 798 views

I'm query my jcr:content for nodes with a certain resource type, however, the query returns ALL nodes under the matched queries. When I iterate over the results with results.getHits(), it iterates all nodes. I only want one level deep from the jcr:content node that I'm searching. I've attempted using "p.nodedepth" with a value of "1", but this doesn't do anything. Any direction would be appreciated.

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 smacdonald2008

Using JCR SQL -- you can use this syntax:
String sql= "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '"+path +"/%' AND NOT jcr:path LIKE '"+path +"/%/%'";

2 replies

smacdonald2008
smacdonald2008Accepted solution
October 16, 2015

Using JCR SQL -- you can use this syntax:
String sql= "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '"+path +"/%' AND NOT jcr:path LIKE '"+path +"/%/%'";

October 16, 2015

How would I write this using the QueryBuilder notation?