Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix broken date range search

Michael Shamoon5e9a7b94ba29
diff --git a/src/documents/views.py b/src/documents/views.py
index 87862fe07..e2807edff 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -468,14 +468,16 @@ 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
- ],
- )
+ 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
+ ],
+ )
r = super().to_representation(doc)
r["__search_hit__"] = {
"score": instance.score,