Legacy Knowledge Base
Published Jun. 30, 2025

Not getting Snippet field in the Document object which is required for Search Summary purpose

Written By

Marcos da Silva Xavier

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Snippet field doesn't get returned after using SearchRequestBuilderFactory to create the Search Request following Liferay's official documentation.

Environment

  • DXP 7.4

Resolution

Summary summary = new Summary(
document.get(prefix + titleField, titleField),
document.get(prefix + contentField, contentField));
Here, the prefix is :-
String prefix = Field.SNIPPET + StringPool.UNDERLINE;

 

...

SearchResponse searchResponse = searcher.search(searchRequest);

SearchHits searchHits = searchResponse.getSearchHits();

List<SearchHit> searchHitsList = searchHits.getSearchHits();

for (SearchHit hit : searchHitsList) {

Document document = hit.getDocument();

...

 

  • But in order to achieve this goal, you must use the SearchResponse function getDocuments71(). This function will return a list of documents that contains the snippet title field and the snippet content field. The code example below may be useful:

 

...
SearchResponse searchResponse = searcher.search(searchRequest);

List<Document> documents = searchResponse.getDocuments71();

for (Document document : documents) {
...

 

 

Did this article resolve your issue ?

Legacy Knowledge Base