mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	comment search highlighting
This commit is contained in:
		| @@ -25,7 +25,13 @@ | ||||
|           </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> | ||||
|  | ||||
|   | ||||
| @@ -10,6 +10,7 @@ export interface SearchHit { | ||||
|   rank?: number | ||||
|  | ||||
|   highlights?: string | ||||
|   comment_highlights?: string | ||||
| } | ||||
|  | ||||
| export interface PaperlessDocument extends ObjectWithId { | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon