Query JCR in exact or like it is in JCR | Community
Skip to main content
Level 3
Nov 9, 2017 2:27 PM UTC
Solved

Query JCR in exact or like it is in JCR

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.
Mallik-VamarajuAccepted solution
Level 3
Nov 9, 2017 5:35 PM UTC

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

Level 3
Nov 10, 2017 11:32 AM UTC

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?

Translate
Mallik-VamarajuAccepted solution
Level 3
Nov 9, 2017 5:35 PM UTC

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.

Translate
smacdonald2008
Level 10
Nov 9, 2017 3:51 PM UTC
Level 3
Nov 9, 2017 3:48 PM UTC

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.

Translate
smacdonald2008
Level 10
Nov 9, 2017 3:34 PM UTC

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

Translate
VeenaVikraman
New Participant
Nov 9, 2017 3:13 PM UTC

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

Translate