Merge pull request #2542 from paperless-ngx/fix-2536

Fix comment search highlight + multi-word search
This commit is contained in:
shamoon
2023-01-27 11:08:36 -08:00
committed by GitHub
3 changed files with 22 additions and 13 deletions

View File

@@ -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
],
)
comments = ",".join(
[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,