diff --git a/src-ui/src/app/components/search/search.component.html b/src-ui/src/app/components/search/search.component.html
index 547c8a475..ae0ec8e3e 100644
--- a/src-ui/src/app/components/search/search.component.html
+++ b/src-ui/src/app/components/search/search.component.html
@@ -16,11 +16,13 @@
{resultCount, plural, =0 {No results} =1 {One result} other {{{resultCount}} results}}
-
+
+
+
+
-
diff --git a/src-ui/src/app/services/rest/search.service.ts b/src-ui/src/app/services/rest/search.service.ts
index 3799f3dc7..e750100fa 100644
--- a/src-ui/src/app/services/rest/search.service.ts
+++ b/src-ui/src/app/services/rest/search.service.ts
@@ -28,7 +28,11 @@ export class SearchService {
}
return this.http.get(`${environment.apiBaseUrl}search/`, {params: httpParams}).pipe(
map(result => {
- result.results.forEach(hit => this.documentService.addObservablesToDocument(hit.document))
+ result.results.forEach(hit => {
+ if (hit.document) {
+ this.documentService.addObservablesToDocument(hit.document)
+ }
+ })
return result
})
)
diff --git a/src/documents/views.py b/src/documents/views.py
index ab4486821..eb9078f75 100755
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -1,3 +1,4 @@
+import logging
import os
import tempfile
from datetime import datetime
@@ -458,12 +459,21 @@ class SearchView(APIView):
self.ix = index.open_index()
def add_infos_to_hit(self, r):
- doc = Document.objects.get(id=r['id'])
+ try:
+ doc = Document.objects.get(id=r['id'])
+ except Document.DoesNotExist:
+ logging.getLogger(__name__).warning(
+ f"Search index returned a non-existing document: "
+ f"id: {r['id']}, title: {r['title']}. "
+ f"Search index needs reindex."
+ )
+ doc = None
+
return {'id': r['id'],
- 'highlights': r.highlights("content", text=doc.content),
+ 'highlights': r.highlights("content", text=doc.content) if doc else None, # NOQA: E501
'score': r.score,
'rank': r.rank,
- 'document': DocumentSerializer(doc).data,
+ 'document': DocumentSerializer(doc).data if doc else None,
'title': r['title']
}