I have tried to highlight the text using:
@Highlight(prefix="<strong>",postfix="</strong>")
Like this:
@Query("articletype:?0")
@Highlight(prefix="<strong>",postfix="</strong>")
ON SOME METHOD
But this doesn't work.
I have even tried to highlight by passing the query as an attr in @Highlight
. But that didn't work.
Please suggest how to use @Highlight
with @Query
to highlight the content.
1.
@Query("field_name:?0")
@Highlight(prefix="<strong>",postfix="</strong>")
public HighlightPage<YOUR_ENTITY_CLASS> yourSomeMethod(String textToBeSearched);
HighlightPage listSolrPage =solrRepository.yourSomeMethod(textToBeSearched);
3.
for (HighlightEntry<YOUR_ENTITY_CLASS> he : listSolrPage.getHighlighted()) {
for (Highlight highlight : he.getHighlights()) {
// Each highlight might have multiple occurrences within the description
StringBuilder sb = new StringBuilder();
for (String snipplet : highlight.getSnipplets()) {
// snipplet contains the highlighted text
slf4jLogger.debug(snipplet);
sb.append(snipplet + "");
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.