How to get 2 excerpts at once in lucene search | Community
Skip to main content
Level 2
August 10, 2023

How to get 2 excerpts at once in lucene search

  • August 10, 2023
  • 1 reply
  • 727 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Nilesh_Mali
Level 3
August 10, 2023

@kiran_22_12  

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); } }

 

 

Level 2
August 10, 2023

Hi @nilesh_mali ,

hit.getExcerpt() method does not expect any arguments as per the Official Documentation. So, this doesnt work.

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/search/result/Hit.html