From c7028d6e87cf5240e7c0f364013fc82570af8b4f Mon Sep 17 00:00:00 2001 From: Their Name Date: Sun, 2 Jan 2022 09:13:32 -0500 Subject: [PATCH] search highlights --- common/index.py | 8 ++++++-- common/templates/common/search_result.html | 2 -- common/templates/partial/list_item_movie.html | 12 +++++++----- common/templatetags/highlight.py | 12 +++++++++--- requirements.txt | 1 + 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/common/index.py b/common/index.py index f9d4bfea..c2389db2 100644 --- a/common/index.py +++ b/common/index.py @@ -153,11 +153,15 @@ class Indexer: # print(r) import types results = types.SimpleNamespace() - results.items = list(map(lambda i: self.item_to_obj(i), r['hits'])) + results.items = list([x for x in map(lambda i: self.item_to_obj(i), r['hits']) if x is not None]) results.num_pages = (r['nbHits'] + SEARCH_PAGE_SIZE - 1) // SEARCH_PAGE_SIZE # print(results) return results @classmethod def item_to_obj(self, item): - return self.class_map[item['_class']].objects.get(id=item['id']) + try: + return self.class_map[item['_class']].objects.get(id=item['id']) + except Exception as e: + logger.error(f"unable to load search result item from db:\n{item}") + return None diff --git a/common/templates/common/search_result.html b/common/templates/common/search_result.html index 2d9e74f2..096adf00 100644 --- a/common/templates/common/search_result.html +++ b/common/templates/common/search_result.html @@ -43,9 +43,7 @@