From ffeed4192e723ce991c2ec1c50f1db78f6928ad5 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 Aug 2018 16:19:21 -0400 Subject: [PATCH] Refresh index before reddit comment callback --- callbacks.py | 1 + search/search.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/callbacks.py b/callbacks.py index f749ee1..647c963 100644 --- a/callbacks.py +++ b/callbacks.py @@ -58,6 +58,7 @@ class RedditCommentCallback(RedditCallback): comment_id = self.task.callback_args["comment_id"] print("Editing comment comment " + comment_id) + search.refresh() # Make sure the newly indexed documents are available before commenting stats = search.get_stats(self.task.website_id) message = self.reddit_bot.get_comment(stats, self.task.website_id, message="There you go! This website was crawled in `" + diff --git a/search/search.py b/search/search.py index 5c1efa8..16439e2 100644 --- a/search/search.py +++ b/search/search.py @@ -31,6 +31,9 @@ class SearchEngine: def get_stats(self, website_id: int, subdir: str = None): raise NotImplementedError + def refresh(self): + raise NotImplementedError + class ElasticSearchEngine(SearchEngine): SORT_ORDERS = { @@ -460,3 +463,6 @@ class ElasticSearchEngine(SearchEngine): for website in websites: if website not in non_empty_websites: yield website + + def refresh(self): + self.es.indices.refresh(self.index_name)