Query JCR in exact or like it is in JCR | Community
Skip to main content
New Participant
November 9, 2017
Solved

Query JCR in exact or like it is in JCR

  • November 9, 2017
  • 6 replies
  • 2953 views

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:

It should be:

  • headline
  • text
  • text
  • image
  • text

Br,

Tim

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 Mallik-Vamaraju

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.

6 replies

New Participant
November 10, 2017

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?

Mallik-VamarajuAccepted solution
New Participant
November 9, 2017

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.

smacdonald2008
New Participant
November 9, 2017
New Participant
November 9, 2017

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.

smacdonald2008
New Participant
November 9, 2017

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

VeenaVikraman
New Participant
November 9, 2017

querybuilder order by default node order   See if this answers your question ??