Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

AEM 6.5 | Search component for content fragments

Avatar

Level 4

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
Community Advisor

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
Community Advisor

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

Community Advisor

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 Advisor

@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...