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

AEM 6.5 | Search component for content fragments

Avatar

Level 2

I am looking to create a custom component to pull content fragments based on type(content fragment model) and/or a field filter. Wondering if anyone from the community has already created such types of components. If yes, could you please share the link?

 

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi 

You can utilize the Query builder concept for searching any type of data in your custom code and write query on the fragment type with path as your root cf path

For more information on query builder please follow this article

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/query-builder/quer...

 

View solution in original post

3 Replies

Avatar

Correct answer by
Level 8

Hi 

You can utilize the Query builder concept for searching any type of data in your custom code and write query on the fragment type with path as your root cf path

For more information on query builder please follow this article

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/query-builder/quer...

 

Avatar

Level 8

Below blog shows exactly how to query the fragments using query builder based on model. Please check it out,

https://aemsimplifiedbynikhil.wordpress.com/2020/10/11/content-fragment-as-java-apis/ 

 

Map<String, String> map = new HashMap<>();
map.put("type", "dam:Asset");
map.put("path", "/content/dam");
map.put("First_property", "jcr:content/contentFragment");
map.put("First_property.value", "true");
map.put("Second_property", "jcr:content/data/cq:model");
map.put("Second_property.value", "conf/fragmentexamples/settings/dam/cfm/models/<your-model-name>");
map.put("property.and", "true");
map.put("p.limit", "-1");

QueryBuilder queryBuilder = request.getResourceResolver().adaptTo(QueryBuilder.class);
Query query = queryBuilder.createQuery(PredicateGroup.create(map),
request.getResourceResolver().adaptTo(Session.class));
final SearchResult result = query.getResult();

Avatar

Employee

@MukeshAEM mostly this can be achieved with Query Builder as pointed by answers below.
But in case of Content Fragments, I personally prefer using GraphQL, which will optimize and would prove to be a better solution in case Content Fragments and Content Fragment Models scale to a larger number. It could also prove to be a better option, if the component requirement get more complex and asks for even more complex queries. Please refer below link to achieve your usecase:

https://github.com/adobe/aem-headless-client-java

 

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...