From ebedaef00b552fff5b3d9db021ee41631d24d617 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 6 Jul 2020 21:43:57 +0000 Subject: [PATCH] Tune search rankings and attributes --- apiserver/search.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apiserver/search.py b/apiserver/search.py index 95341aa..e747bbd 100644 --- a/apiserver/search.py +++ b/apiserver/search.py @@ -20,8 +20,36 @@ def create_index(): logging.error('Problem creating MeiliSearch index: {}'.format(str(e))) return False +def update_rankings(): + try: + json = ['typo', 'words', 'proximity', 'attribute', 'desc(date)', 'wordsPosition', 'exactness'] + r = requests.post(MEILI_URL + 'indexes/qotnews/settings/ranking-rules', json=json, timeout=2) + if r.status_code != 202: + raise Exception('Bad response code ' + str(r.status_code)) + return r.json() + except KeyboardInterrupt: + raise + except BaseException as e: + logging.error('Problem setting MeiliSearch ranking rules: {}'.format(str(e))) + return False + +def update_attributes(): + try: + json = ['title', 'url', 'author', 'link', 'id'] + r = requests.post(MEILI_URL + 'indexes/qotnews/settings/searchable-attributes', json=json, timeout=2) + if r.status_code != 202: + raise Exception('Bad response code ' + str(r.status_code)) + return r.json() + except KeyboardInterrupt: + raise + except BaseException as e: + logging.error('Problem setting MeiliSearch searchable attributes: {}'.format(str(e))) + return False + def init(): create_index() + update_rankings() + update_attributes() def put_story(story): story = story.copy()