I have used p.excerpt=true in my aem query. And while extracting the excerpts using hit.getExcerpt(), I am getting a single sentence like.. "We are specialized in <strong>health</strong> care centres..." .
How do I get two such sentences . eg: "We are specialized in <strong>health</strong> care centres... with the help of World <strong>Health</strong> Organization.."
Views
Replies
Total Likes
commentUtil.getExcerpts will help you like below
SearchResult result = query.getResult();
List<Hit> hits = result.getHits();
// Get the ExcerptProvider
ExcerptProvider excerptProvider = resourceResolver.adaptTo(ExcerptProvider.class);
// Retrieve and output excerpts from the hits
int numExcerpts = 2; // Number of excerpts you want to retrieve
for (Hit hit : hits) {
Resource resource = hit.getResource();
// Get the excerpts
List<String> excerpts = excerptProvider.getExcerpts(resource, searchTerm, numExcerpts);
// Output the excerpts
System.out.println("Excerpts for " + resource.getPath() + ":");
for (String excerpt : excerpts) {
System.out.println("- " + excerpt);
}
}
Hi @Nilesh_Mali ,
hit.getExcerpt() method does not expect any arguments as per the Official Documentation. So, this doesnt work.