How to perform the following using sql2 query:
Requirement:
path: /content/consumer
- go one node level, for example : /content/consumer/en-us
- search for String authored in a pathfield like "/content/consumer/en-us"
- if
(current Node != Pathfield)
then display it.
repeat the step from 1 to 3 all other locales(en-ca, fr-fr, de-de etc).
Here is what I have tried:
SELECT parent.* FROM [nt:unstructured] AS parent INNER JOIN [nt:unstructured] AS child ON ISDESCENDANTNODE(child,parent) WHERE ISDESCENDANTNODE(parent, [/content/consumer/en-us/]) AND child.[*] = '/content/consumer/%'
The query read or traversed more than 100000 nodes. To avoid affecting other tasks, processing was stopped.
If I run:
SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE('/content/consumer/en-us/ip') and s.* LIKE '/content/consumer/%'
This will display all paths irrespective of local. What I am looking for is: /content/consumer/[^en-us]% (i.e not like en-us).
Here is what I have done so far:
Resource resource = request.getResourceResolver().getResource(path);
Node node = resource.adaptTo(Node.class);
ResourceResolver resourceResolver = request.getResourceResolver();
try {
NodeIterator list = node.getNodes();
while (list.hasNext()) {
Node currentSubNode = list.nextNode();
subNodeName = currentSubNode.getPath();
culture = extractCultureNodeName(subNodeName);
fullTextPath = path + culture;
Map<String, String> map = new HashMap<String, String>();
map.put("type", "nt:base");
map.put("path", subNodeName);
map.put("fulltext", fullTextPath);
if (StringUtils.isNotBlank(culture)) {
Query query = queryBuilder.createQuery(PredicateGroup.create(map),
resourceResolver.adaptTo(Session.class));
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
String output = hit.getPath();
LOG.info("HITs: " + hit.getPath());
}
}
}
The problem is in the query builder, the number of hits I am getting is far less than bare xpath query in crxde:
/jcr:root/content/consumer/en-us//element(*, nt:base)
[
(jcr:contains(., ‘/content/consumer/en-us’))
]