]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
comment search highlighting 2351/head
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Jan 2023 03:06:51 +0000 (19:06 -0800)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Jan 2023 03:06:51 +0000 (19:06 -0800)
src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html
src-ui/src/app/data/paperless-document.ts
src/documents/views.py

index 80aedb7f2bdb7f6f80a3dcea4af346138cb12b15..0eb965a22ee94924e852bb9b2556671f5dc72fe4 100644 (file)
           </h5>
         </div>
         <p class="card-text">
-          <span *ngIf="document.__search_hit__" [innerHtml]="document.__search_hit__.highlights"></span>
+          <span *ngIf="document.__search_hit__ && document.__search_hit__.highlights" [innerHtml]="document.__search_hit__.highlights"></span>
+          <span *ngIf="document.__search_hit__ && document.__search_hit__.comment_highlights">
+            <svg width="1em" height="1em" fill="currentColor" class="me-2">
+              <use xlink:href="assets/bootstrap-icons.svg#chat-left-text"/>
+            </svg>
+            <span [innerHtml]="document.__search_hit__.comment_highlights"></span>
+          </span>
           <span *ngIf="!document.__search_hit__" class="result-content">{{contentTrimmed}}</span>
         </p>
 
index 8b038d79e72eb70623456fc54b9b12a1ff38fa27..cdee624af6468ad8eef8456cda1f9b255150baa3 100644 (file)
@@ -10,6 +10,7 @@ export interface SearchHit {
   rank?: number
 
   highlights?: string
+  comment_highlights?: string
 }
 
 export interface PaperlessDocument extends ObjectWithId {
index e313ae17ea79c57bfcbb69815d2fbb8214adac37..c65b6f0b4b6d4dd8f3cc2b899d39a15f88c8d719 100644 (file)
@@ -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,