In this article we will go through different APIs of content fragment which we can use while exposing or customizing the behavior of CF.
To start with lets understand how we get the related content fragment of a specific model using a query builder.
First we start with adding the specific properties to the map and running a query:
Map<String, String> map = new HashMap<>();
Once we are done creating the map we will create our query variable using the request:
QueryBuilder queryBuilder = request.getResourceResolver().adaptTo(QueryBuilder.class);
Now we will get the results using query and the map using Predicategroup:
Query query = queryBuilder.createQuery(PredicateGroup.create(map),
final SearchResult result = query.getResult();
This result variable will hold all the Content fragment used by the specified content model at location /content/dam(we defined while creating the map).
Now we can iterate on the results and get the specified resource and adapt it to ContentFragment interface which holds all the content fragment related APIs.