-
StackOverflow 文件
-
solrj 教程
-
使用 SolrJ 獲取突出顯示的片段
-
獲取單值欄位的突出顯示文字
public String getHighlightedText(final QueryResponse queryResponse, final String fieldName, final String docId) {
String highlightedText = "";
Map<String, Map<String, List<String>>> highlights = queryResponse.getHighlighting();
if (highlights!=null && MapUtils.isNotEmpty(highlights.get(docId))) {
List<String> snippets = highlights.get(docId).get(fieldName);
if (CollectionUtils.isNotEmpty(snippets)) {
highlightedText = getFragments(snippets);
}
}
return highlightedText;
}
private static final String getFragments(List<String> snippets){
StringBuilder fragments = new StringBuilder();
for (int i = 0; i < snippets.size(); i++) {
if (i > 0) {
fragments.append("............");
}
fragments.append(snippets.get(i));
}
return fragments.toString();
}