mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-08-12 14:21:01 +00:00
fix: 新增拼音
This commit is contained in:
@@ -343,7 +343,17 @@ public class SearchService {
|
|||||||
.preTags("<mark>")
|
.preTags("<mark>")
|
||||||
.postTags("</mark>")
|
.postTags("</mark>")
|
||||||
.fields("title", f -> f.fragmentSize(highlightFragmentSize()).numberOfFragments(1))
|
.fields("title", f -> f.fragmentSize(highlightFragmentSize()).numberOfFragments(1))
|
||||||
|
.fields("title.py", f -> f.fragmentSize(highlightFragmentSize()).numberOfFragments(1))
|
||||||
.fields("content", f -> f.fragmentSize(highlightFragmentSize()).numberOfFragments(1))
|
.fields("content", f -> f.fragmentSize(highlightFragmentSize()).numberOfFragments(1))
|
||||||
|
.fields("content.py", f ->
|
||||||
|
f.fragmentSize(highlightFragmentSize()).numberOfFragments(1)
|
||||||
|
)
|
||||||
|
.fields("author", f -> f.numberOfFragments(0))
|
||||||
|
.fields("author.py", f -> f.numberOfFragments(0))
|
||||||
|
.fields("category", f -> f.numberOfFragments(0))
|
||||||
|
.fields("category.py", f -> f.numberOfFragments(0))
|
||||||
|
.fields("tags", f -> f.numberOfFragments(0))
|
||||||
|
.fields("tags.py", f -> f.numberOfFragments(0))
|
||||||
)
|
)
|
||||||
.size(DEFAULT_OPEN_SEARCH_LIMIT > 0 ? DEFAULT_OPEN_SEARCH_LIMIT : 10),
|
.size(DEFAULT_OPEN_SEARCH_LIMIT > 0 ? DEFAULT_OPEN_SEARCH_LIMIT : 10),
|
||||||
SearchDocument.class
|
SearchDocument.class
|
||||||
@@ -425,8 +435,10 @@ public class SearchService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, List<String>> highlight = hit.highlight();
|
Map<String, List<String>> highlight = hit.highlight();
|
||||||
String highlightedContent = firstHighlight(highlight, "content");
|
String highlightedContent = firstHighlight(highlight, "content", "content.py");
|
||||||
String highlightedTitle = firstHighlight(highlight, "title");
|
String highlightedTitle = firstHighlight(highlight, "title", "title.py");
|
||||||
|
String highlightedAuthor = firstHighlight(highlight, "author", "author.py");
|
||||||
|
String highlightedCategory = firstHighlight(highlight, "category", "category.py");
|
||||||
boolean highlightTitle = highlightedTitle != null && !highlightedTitle.isBlank();
|
boolean highlightTitle = highlightedTitle != null && !highlightedTitle.isBlank();
|
||||||
String documentType = document.type() != null ? document.type() : "";
|
String documentType = document.type() != null ? document.type() : "";
|
||||||
String effectiveType = documentType;
|
String effectiveType = documentType;
|
||||||
@@ -465,7 +477,18 @@ public class SearchService {
|
|||||||
String highlightedText = highlightTitle
|
String highlightedText = highlightTitle
|
||||||
? highlightedTitle
|
? highlightedTitle
|
||||||
: highlightHtml(document.title(), keyword);
|
: highlightHtml(document.title(), keyword);
|
||||||
String highlightedSubText = highlightHtml(subText, keyword);
|
String highlightedSubText;
|
||||||
|
if ("comment".equals(documentType)) {
|
||||||
|
highlightedSubText = highlightedAuthor != null && !highlightedAuthor.isBlank()
|
||||||
|
? highlightedAuthor
|
||||||
|
: highlightHtml(subText, keyword);
|
||||||
|
} else if ("post".equals(documentType) || "post_title".equals(effectiveType)) {
|
||||||
|
highlightedSubText = highlightedCategory != null && !highlightedCategory.isBlank()
|
||||||
|
? highlightedCategory
|
||||||
|
: highlightHtml(subText, keyword);
|
||||||
|
} else {
|
||||||
|
highlightedSubText = highlightHtml(subText, keyword);
|
||||||
|
}
|
||||||
String highlightedExtra = snippetHtml != null ? snippetHtml : highlightHtml(snippet, keyword);
|
String highlightedExtra = snippetHtml != null ? snippetHtml : highlightHtml(snippet, keyword);
|
||||||
return new SearchResult(
|
return new SearchResult(
|
||||||
effectiveType,
|
effectiveType,
|
||||||
@@ -480,15 +503,25 @@ public class SearchService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String firstHighlight(Map<String, List<String>> highlight, String field) {
|
private String firstHighlight(Map<String, List<String>> highlight, String... fields) {
|
||||||
if (highlight == null || field == null) {
|
if (highlight == null || fields == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<String> values = highlight.get(field);
|
for (String field : fields) {
|
||||||
if (values == null || values.isEmpty()) {
|
if (field == null) {
|
||||||
return null;
|
continue;
|
||||||
|
}
|
||||||
|
List<String> values = highlight.get(field);
|
||||||
|
if (values == null || values.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return values.get(0);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cleanHighlight(String value) {
|
private String cleanHighlight(String value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user