Merge branch 'dev' into feature-permissions

This commit is contained in:
Michael Shamoon
2023-01-27 12:35:48 -08:00
21 changed files with 854 additions and 389 deletions

View File

@@ -481,6 +481,10 @@ class DocumentViewSet(
)
c.save()
from documents import index
index.add_or_update_document(self.get_object())
return Response(self.getComments(doc))
except Exception as e:
logger.warning(f"An error occurred saving comment: {str(e)}")
@@ -492,6 +496,11 @@ class DocumentViewSet(
elif request.method == "DELETE":
comment = Comment.objects.get(id=int(request.GET.get("id")))
comment.delete()
from documents import index
index.add_or_update_document(self.get_object())
return Response(self.getComments(doc))
return Response(
@@ -504,21 +513,14 @@ class DocumentViewSet(
class SearchResultSerializer(DocumentSerializer, PassUserMixin):
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,