From 807e32c61f7c2542837d7d2b3e0e3dca05e326ee Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 8 Apr 2026 21:32:57 -0700 Subject: [PATCH] Adapt frontend to when highlight is empty --- .../document-card-large.component.html | 4 ++-- .../document-card-large.component.spec.ts | 13 +++++++++++++ .../document-card-large.component.ts | 11 +++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html index f0da79260..1c69d0f53 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html @@ -43,7 +43,7 @@
@if (document) { - @if (document.__search_hit__ && document.__search_hit__.highlights) { + @if (hasSearchHighlights) { } @for (highlight of searchNoteHighlights; track highlight) { @@ -52,7 +52,7 @@ } - @if (!document.__search_hit__?.score) { + @if (shouldShowContentFallback) { {{contentTrimmed}} } } @else { diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts index 4d62c6a0a..e4e2bca74 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts @@ -127,6 +127,19 @@ describe('DocumentCardLargeComponent', () => { expect(component.searchNoteHighlights).toContain('bananas') }) + it('should fall back to document content when a search hit has no highlights', () => { + component.document.__search_hit__ = { + score: 0.9, + rank: 1, + highlights: '', + note_highlights: null, + } + fixture.detectChanges() + + expect(fixture.nativeElement.textContent).toContain('Cupcake ipsum') + expect(component.shouldShowContentFallback).toBe(true) + }) + it('should try to close the preview on mouse leave', () => { component.popupPreview = { close: jest.fn(), diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts index 74dccfaf3..8f77489ec 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts @@ -164,6 +164,17 @@ export class DocumentCardLargeComponent ) } + get hasSearchHighlights() { + return Boolean(this.document?.__search_hit__?.highlights?.trim()?.length) + } + + get shouldShowContentFallback() { + return ( + this.document?.__search_hit__?.score == null || + (!this.hasSearchHighlights && this.searchNoteHighlights.length === 0) + ) + } + get notesEnabled(): boolean { return this.settingsService.get(SETTINGS_KEYS.NOTES_ENABLED) }