Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Query JCR in exact or like it is in JCR

tim-schwalbe-NZ
Level 4
Level 4

Hello everyone,

I query the JCR with the following query:

String queryString = "SELECT * FROM [nt:unstructured] AS node WHERE ISDESCENDANTNODE(node,'" + subPagePath + "') AND (NAME() like 'headline%' or NAME() like 'text%' or NAME() like'image%')";

It works as expected but the ordering of the nodes is not like the ordering in crxde. Is there a way to get the elements in the exact same ordering like in crxde?

I want to recreate the structure of a Page and deliver it to another App.

So if there is this structure:

1344701_pastedImage_0.png

It should be:

  • headline
  • text
  • text
  • image
  • text

Br,

Tim

1 Accepted Solution
Mallik-Vamaraju
Correct answer by
Level 3
Level 3

please check this out Query for fetching assets with the same ordering as used in DAM

If you want to maintain the order, the suggested practice is to use JCR API as opposed to query. It also betters the performance.

View solution in original post

0 Replies
smacdonald2008
Level 10
Level 10

You want to move the node structure to another part of the AEM JCR?

tim-schwalbe-NZ
Level 4
Level 4

No, I want use the Page content for An mobile App or rss feed. So I need the tree structure of the Page to build a list of content and put it in a differrent HTML Format, json or XML.

So I thought Read out the nodes in the order like it is in the tree and create for example an XML out of it.

Which contains headline, Text and Image Tags. But to recreate a Page in another Page I need to order the Elements. Maybe there is a better way?

Thanks so far.

Mallik-Vamaraju
Correct answer by
Level 3
Level 3

please check this out Query for fetching assets with the same ordering as used in DAM

If you want to maintain the order, the suggested practice is to use JCR API as opposed to query. It also betters the performance.

View solution in original post

tim-schwalbe-NZ
Level 4
Level 4

I did now change the code to this, but it still orders the nodes unnatural.

map.put("path", "/content/press-releases/2017/2017-aaaa");
map.put("group.p.or", "true");
map.put("group.1_property", "sling:resourceType");
map.put("group.1_property.value", "aaaa/components/content/text");
map.put("group.2_property", "sling:resourceType");
map.put("group.2_property.value", "aaaa/components/content/headline");
map.put("group.3_property", "sling:resourceType");
map.put("group.3_property.value", "aaaa/components/content/image");
map.put("orderby", "@path");

Query query = queryBuilder.createQuery(PredicateGroup.create(map), session);
query.setStart(0);
query.setHitsPerPage(-1);

SearchResult result = query.getResult();
Long sum = result.getTotalMatches();
Iterator<Node> nodes = result.getNodes();
nodes.forEachRemaining(node -> {

   try {

  String name = node.getName();
   } catch (RepositoryException e) {

  e.printStackTrace();
   }

});

querybuilder order by default node order

QueryBuilder Debugger does not support it because usually you don't have a search when you want the node order. can simply use navigational access (node.getNodes()) in case you want node order.

But then I have the problem again to get all nodes of a branch.

So both solutions are not working...what to do now?

Should I iterate recursively through the nodes?