From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 5 Jan 2023 03:06:51 +0000 (-0800) Subject: comment search highlighting X-Git-Tag: v1.12.0-beta.rc0~71^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2351%2Fhead;p=thirdparty%2Fpaperless-ngx.git comment search highlighting --- 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 80aedb7f2b..0eb965a22e 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 @@ -25,7 +25,13 @@
- + + + + + {{contentTrimmed}}
diff --git a/src-ui/src/app/data/paperless-document.ts b/src-ui/src/app/data/paperless-document.ts index 8b038d79e7..cdee624af6 100644 --- a/src-ui/src/app/data/paperless-document.ts +++ b/src-ui/src/app/data/paperless-document.ts @@ -10,6 +10,7 @@ export interface SearchHit { rank?: number highlights?: string + comment_highlights?: string } export interface PaperlessDocument extends ObjectWithId { diff --git a/src/documents/views.py b/src/documents/views.py index e313ae17ea..c65b6f0b4b 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -458,10 +458,19 @@ class DocumentViewSet( class SearchResultSerializer(DocumentSerializer): def to_representation(self, instance): doc = Document.objects.get(id=instance["id"]) + commentTerm = instance.results.q.subqueries[0] + comments = ",".join( + [ + str(c.comment) + for c in Comment.objects.filter(document=instance["id"]) + if commentTerm.text in c.comment + ], + ) r = super().to_representation(doc) r["__search_hit__"] = { "score": instance.score, - "highlights": instance.highlights("content", text=doc.content) + "highlights": instance.highlights("content", text=doc.content), + "comment_highlights": instance.highlights("content", text=comments) if doc else None, "rank": instance.rank,