Hi,
I am trying to filter out Content Fragment using ResourceFilterStream, but cannot do so using .setChildSelector("[jcr:content/metadata/cq:tags]
Doing something like below.
Resource resource = resourceResolver.getResource("/content/dam/test-site");
ResourceFilterStream rfs = resource.adaptTo(ResourceFilterStream.class);
rfs.setBranchSelector("[jcr:primaryType] == 'dam:Asset'")
.setChildSelector("[jcr:content/metadata/cq:tags] like 'test-site:test'")
.stream()
.forEach(r-> logger.info("found resource {}",r.getPath()));
what should be the .setChildSelector
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
@Aakarsh For CF with tags via Properties screen
property in CRXDE:
Query:
ResourceFilterStream rfs = resource.adaptTo(ResourceFilterStream.class);
rfs
.setBranchSelector("[jcr:primaryType] != 'dam:Asset'")
.setChildSelector("[jcr:content/metadata/cq:tags] contains $tag").addParam("tag", "properties:orientation/landscape")
.stream()
.forEach(r -> {
try {
resp.getWriter().println("Path: " + r.getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
Result:
Hi @Aakarsh
You should be using the JCR queries to find out the fragments. The advantages with JCR queries are you can leverage the index.
Example
SELECT * FROM [dam:Asset] AS cf
WHERE ISDESCENDANTNODE(cf, '/content/dam/test-site')
AND cf.[jcr:content/metadata/cq:tags] IN ('tag1', 'tag2', 'tag3')
Note: Please check the property name and path and adjust accordingly
Hi Arun,
Thank for the prompt reply, but I am familiar with JCR and SQL2 queries, wanted to use ResourceFilterStream as there are many small queries which get fired on every page load. Not using caching to wanted to use this for optimized tree traversal.
Please try with following code:
ResourceFilterStream rfs = resource.adaptTo(ResourceFilterStream.class);
rfs
.setBranchSelector("[jcr:primaryType] != 'dam:Asset'")
.setChildSelector("[jcr:content/metadata/cq:tags] contains $tag").addParam("tag", "properties:orientation/landscape")
.stream()
.forEach(r -> {
try {
resp.getWriter().println("Path: " + r.getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
.setBranchSelector("[jcr:primaryType] != 'dam:Asset'")
this would not pick the content fragments.
.setChildSelector("[jcr:content/metadata/cq:tags] contains $tag").addParam("tag", "properties:orientation/landscape")
is still not able to pick tags.
Hello @Aakarsh
If you are adding the tags via CF properties, then the previous should work.
If you are adding it to a variation, via CF Edit, then its more dynamic. Please confirm, it its variation
@Aakarsh For CF with tags via Properties screen
property in CRXDE:
Query:
ResourceFilterStream rfs = resource.adaptTo(ResourceFilterStream.class);
rfs
.setBranchSelector("[jcr:primaryType] != 'dam:Asset'")
.setChildSelector("[jcr:content/metadata/cq:tags] contains $tag").addParam("tag", "properties:orientation/landscape")
.stream()
.forEach(r -> {
try {
resp.getWriter().println("Path: " + r.getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
Result:
@Aakarsh Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
this worked for me
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("first", Tag);
paramMap.put("second", "true");
Resource resource = resourceResolver.getResource(CONTENT_FRAGMENT_PATH);
ResourceFilterStream resourceFilterStream = resource.adaptTo(ResourceFilterStream.class);
TagCount = (int) resourceFilterStream.setBranchSelector("[jcr:primaryType] == 'dam:Asset'")
.setChildSelector("[jcr:content/metadata/cq:tags] contains $first && [jcr:content/data/master/isActive] like $second")
.addParams(paramMap)
.stream()
.count();
Views
Replies
Total Likes
Views
Likes
Replies