From b869ad02a1f1fe05f789ac4a7adb917fdd571bc1 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 4 Jan 2023 19:06:51 -0800 Subject: [PATCH] comment search highlighting --- .../document-card-large.component.html | 8 +++++++- src-ui/src/app/data/paperless-document.ts | 1 + src/documents/views.py | 11 ++++++++++- 3 files changed, 18 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 80aedb7f2..0eb965a22 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 8b038d79e..cdee624af 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 e313ae17e..c65b6f0b4 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,