mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-03 17:27:50 +02:00
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:
committed by
GitHub
parent
5b700dc0c7
commit
bc86ed4474
@@ -123,6 +123,24 @@ class LuceneHighlighterTest {
|
||||
assertThat(contentFragments[0].isMatchesContentEnd()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMatchContentStartWithDefaultAnalyzer() throws InvalidTokenOffsetsException, IOException {
|
||||
ContentFragment[] contentFragments = highlight("GameOfLife.java", "gameoflife");
|
||||
|
||||
assertThat(contentFragments).hasSize(1);
|
||||
assertThat(contentFragments[0].isMatchesContentStart()).isTrue();
|
||||
assertThat(contentFragments[0].isMatchesContentEnd()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMatchContentEndWithDefaultAnalyzer() throws InvalidTokenOffsetsException, IOException {
|
||||
ContentFragment[] contentFragments = highlight("Button.tsx", "default");
|
||||
|
||||
assertThat(contentFragments).hasSize(1);
|
||||
assertThat(contentFragments[0].isMatchesContentStart()).isFalse();
|
||||
assertThat(contentFragments[0].isMatchesContentEnd()).isTrue();
|
||||
}
|
||||
|
||||
@Nested
|
||||
class IsHighlightableTests {
|
||||
|
||||
@@ -162,6 +180,16 @@ class LuceneHighlighterTest {
|
||||
|
||||
}
|
||||
|
||||
private ContentFragment[] highlight(String resource, String search) throws IOException, InvalidTokenOffsetsException {
|
||||
StandardAnalyzer analyzer = new StandardAnalyzer();
|
||||
Query query = new TermQuery(new Term("content", search));
|
||||
|
||||
String content = content(resource);
|
||||
|
||||
LuceneHighlighter highlighter = new LuceneHighlighter(analyzer, query);
|
||||
return highlighter.highlight("content", Indexed.Analyzer.DEFAULT, content);
|
||||
}
|
||||
|
||||
private ContentFragment[] highlightCode(String resource, String search) throws IOException, InvalidTokenOffsetsException {
|
||||
NonNaturalLanguageAnalyzer analyzer = new NonNaturalLanguageAnalyzer();
|
||||
Query query = new TermQuery(new Term("content", search));
|
||||
|
||||
Reference in New Issue
Block a user