Display search result fixes (#1901)

Fix syntax highlighting on non highlighted fields. Fix ellipsis on new lines in code syntax highlighting. Fix ellipsis on content start or end in non code fields.

Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
This commit is contained in:
Matthias Thieroff
2021-12-21 15:10:08 +01:00
committed by GitHub
parent 5b700dc0c7
commit bc86ed4474
8 changed files with 455 additions and 82 deletions

View File

@@ -75,7 +75,7 @@ public final class LuceneHighlighter {
if (fieldAnalyzer == Indexed.Analyzer.CODE) {
return keepWholeLine(value, fragments);
}
return Arrays.stream(fragments).map(ContentFragment::new)
return Arrays.stream(fragments).map(f -> createContentFragment(value, f))
.toArray(ContentFragment[]::new);
}
@@ -122,4 +122,9 @@ public final class LuceneHighlighter {
return new ContentFragment(snippet + content.substring(index + raw.length(), end) + (matchesContentEnd ? "" : "\n"), matchesContentStart, matchesContentEnd);
}
private ContentFragment createContentFragment(String content, String fragment) {
String raw = fragment.replace(PRE_TAG, "").replace(POST_TAG, "");
return new ContentFragment(fragment, content.startsWith(raw), content.endsWith(raw));
}
}