mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-04 03:27:12 -05:00 
			
		
		
		
	Merge pull request #2542 from paperless-ngx/fix-2536
Fix comment search highlight + multi-word search
This commit is contained in:
		
						commit
						d2b290f789
					
				@ -26,11 +26,11 @@
 | 
			
		||||
        </div>
 | 
			
		||||
        <p class="card-text">
 | 
			
		||||
          <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" class="d-block">
 | 
			
		||||
          <span *ngFor="let highlight of searchCommentHighlights" class="d-block">
 | 
			
		||||
            <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 [innerHtml]="highlight"></span>
 | 
			
		||||
          </span>
 | 
			
		||||
          <span *ngIf="!document.__search_hit__" class="result-content">{{contentTrimmed}}</span>
 | 
			
		||||
        </p>
 | 
			
		||||
 | 
			
		||||
@ -70,6 +70,22 @@ export class DocumentCardLargeComponent {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  get searchCommentHighlights() {
 | 
			
		||||
    let highlights = []
 | 
			
		||||
    if (
 | 
			
		||||
      this.document['__search_hit__'] &&
 | 
			
		||||
      this.document['__search_hit__'].comment_highlights
 | 
			
		||||
    ) {
 | 
			
		||||
      // only show comments with a match
 | 
			
		||||
      highlights = (
 | 
			
		||||
        this.document['__search_hit__'].comment_highlights as string
 | 
			
		||||
      )
 | 
			
		||||
        .split(',')
 | 
			
		||||
        .filter((higlight) => higlight.includes('<span'))
 | 
			
		||||
    }
 | 
			
		||||
    return highlights
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getIsThumbInverted() {
 | 
			
		||||
    return this.settingsService.get(SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -477,21 +477,14 @@ class DocumentViewSet(
 | 
			
		||||
class SearchResultSerializer(DocumentSerializer):
 | 
			
		||||
    def to_representation(self, instance):
 | 
			
		||||
        doc = Document.objects.get(id=instance["id"])
 | 
			
		||||
        comments = ""
 | 
			
		||||
        if hasattr(instance.results.q, "subqueries"):
 | 
			
		||||
            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
 | 
			
		||||
                ],
 | 
			
		||||
            [str(c.comment) for c in Comment.objects.filter(document=instance["id"])],
 | 
			
		||||
        )
 | 
			
		||||
        r = super().to_representation(doc)
 | 
			
		||||
        r["__search_hit__"] = {
 | 
			
		||||
            "score": instance.score,
 | 
			
		||||
            "highlights": instance.highlights("content", text=doc.content),
 | 
			
		||||
            "comment_highlights": instance.highlights("content", text=comments)
 | 
			
		||||
            "comment_highlights": instance.highlights("comments", text=comments)
 | 
			
		||||
            if doc
 | 
			
		||||
            else None,
 | 
			
		||||
            "rank": instance.rank,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user