legacy-knowledge-base
公開されました Jun. 30, 2025

検索サマリーのために必要なDocumentオブジェクトのSnippetフィールドが取得されない。

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

learn-legacy-article-disclaimer-text

問題

  • Liferay の公式ドキュメントに従って SearchRequestBuilderFactory を使って Search Request を作成した後、Snippet フィールドが返されません。

環境

  • DXP 7.4

解像度

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

...

  • しかし、この目標を達成するためには、 SearchResponse関数 getDocuments71()を使用しなければならない。 この関数は、スニペットタイトルフィールドとスニペットコンテンツフィールドを含むドキュメントのリストを返します。 以下のコード例が参考になるだろう:

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

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

for (Document document : documents) {
...

did-this-article-resolve-your-issue

legacy-knowledge-base