mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix whoosh auto-highlighting for comments
This commit is contained in:
parent
590d129cd3
commit
44212d492d
@ -477,21 +477,14 @@ class DocumentViewSet(
|
|||||||
class SearchResultSerializer(DocumentSerializer):
|
class SearchResultSerializer(DocumentSerializer):
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
doc = Document.objects.get(id=instance["id"])
|
doc = Document.objects.get(id=instance["id"])
|
||||||
comments = ""
|
comments = ",".join(
|
||||||
if hasattr(instance.results.q, "subqueries"):
|
[str(c.comment) for c in Comment.objects.filter(document=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 = super().to_representation(doc)
|
||||||
r["__search_hit__"] = {
|
r["__search_hit__"] = {
|
||||||
"score": instance.score,
|
"score": instance.score,
|
||||||
"highlights": instance.highlights("content", text=doc.content),
|
"highlights": instance.highlights("content", text=doc.content),
|
||||||
"comment_highlights": instance.highlights("content", text=comments)
|
"comment_highlights": instance.highlights("comments", text=comments)
|
||||||
if doc
|
if doc
|
||||||
else None,
|
else None,
|
||||||
"rank": instance.rank,
|
"rank": instance.rank,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user