1
내 응용 프로그램을 Lucene에서 Solr로 마이그레이션 중입니다.SolrJ를 사용하여 강조된 미리보기를 얻으려면 어떻게해야합니까?
{
"id":"fdc3833a-0e4f-4314-ba8c",
"title": "Paris is a beautiful city",
"description": "The city is a great example of......",
}
"highlighting": {
"fdc3833a-0e4f-4314-ba8c": {
"title": [
"Paris is a beautiful <b>city</b>"
],
"description": [
"The <b>city</b> is a great example of......"
]
}
}
:
{
"id":"fdc3833a-0e4f-4314-ba8c",
"title": "Paris is a beautiful <b>city</b>",
"description": "The <b>city</b> is a great example of......",
}
내가 대신 다음과 같은 반응을 얻고있는 동안 : SOLR, 나는 같은 반응을 기대 예를 들어 나는 키워드 "도시"를 검색하지만 경우에 더 많이 강조 처리 보시다시피, 결과 내에서 강조된 용어를 얻는 대신, 강조 표시라는 추가 섹션이 생기고 있습니다. 이는 Java 코드가 변경되어야 함을 의미합니다. 제 질문은 : 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();
}
당신은 멀티에 대한 몇 가지 변화가 필요합니다 동안이 코드는 당신이 단일 값 필드에 가장 적합한 미리보기를 얻을 것이다주의하십시오 SolrJ에서