From db6e41177bd00d9ed7bfd145d98aded6e90bb26c Mon Sep 17 00:00:00 2001 From: Tanner Date: Thu, 12 Nov 2026 20:03:38 +0000 Subject: [PATCH] Upgrade meilisearch to v1.56.2 --- apiserver/scripts/reindex.py | 20 ++++++++++++++++++-- apiserver/search.py | 16 ++++++++-------- searchserver/README.md | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apiserver/scripts/reindex.py b/apiserver/scripts/reindex.py index ee1334c..f93927e 100644 --- a/apiserver/scripts/reindex.py +++ b/apiserver/scripts/reindex.py @@ -49,10 +49,26 @@ if __name__ == '__main__': count += 1 res = put_stories(stories) - update_id = res['uid'] + if not isinstance(res, dict): + raise RuntimeError('Meilisearch failed to enqueue documents: {}'.format(res)) + + # Meilisearch task responses expose the asynchronous task ID as taskUid. + update_id = res.get('taskUid') or res.get('uid') + if update_id is None: + raise RuntimeError('Meilisearch response did not include a task ID: {}'.format(res)) print('Waiting for processing', end='') - while get_update(update_id)['status'] != 'succeeded': + while True: + task = get_update(update_id) + if not isinstance(task, dict): + raise RuntimeError('Could not retrieve Meilisearch task {}: {}'.format(update_id, task)) + + status = task.get('status') + if status == 'succeeded': + break + if status in ('failed', 'canceled'): + raise RuntimeError('Meilisearch task {} {}: {}'.format(update_id, status, task)) + time.sleep(0.5) print('.', end='', flush=True) diff --git a/apiserver/search.py b/apiserver/search.py index f3bee36..6c4f3aa 100644 --- a/apiserver/search.py +++ b/apiserver/search.py @@ -25,17 +25,17 @@ def meili_api(method, route, json=None, params=None, parse_json=True): logging.error('Problem with MeiliSearch api route: %s: %s', route, str(e)) return False -def create_index(): - json = dict(uid='qotnews', primaryKey='id') +def create_index(index_uid='qotnews'): + json = dict(uid=index_uid, primaryKey='id') return meili_api(requests.post, 'indexes', json=json) -def update_settings(): +def update_settings(index_uid='qotnews'): json = { 'rankingRules': ['typo', 'words', 'proximity', 'date:desc', 'exactness'], 'searchableAttributes': ['title', 'url', 'author'], 'displayedAttributes': ['id', 'ref', 'source', 'author', 'author_link', 'score', 'date', 'title', 'link', 'url', 'num_comments'], } - return meili_api(requests.post, 'indexes/qotnews/settings', json=json) + return meili_api(requests.patch, 'indexes/{}/settings'.format(index_uid), json=json) def init(): if not SEARCH_ENABLED: @@ -44,14 +44,14 @@ def init(): print(create_index()) update_settings() -def put_story(story): +def put_story(story, index_uid='qotnews'): if not SEARCH_ENABLED: return - return meili_api(requests.post, 'indexes/qotnews/documents', [story]) + return meili_api(requests.post, 'indexes/{}/documents'.format(index_uid), [story]) -def search(q): +def search(q, index_uid='qotnews'): if not SEARCH_ENABLED: return [] json = dict(q=q, limit=settings.FEED_LENGTH) - r = meili_api(requests.post, 'indexes/qotnews/search', json=json, parse_json=False) + r = meili_api(requests.post, 'indexes/{}/search'.format(index_uid), json=json, parse_json=False) return r if __name__ == '__main__': diff --git a/searchserver/README.md b/searchserver/README.md index 0bbeded..ac137ea 100644 --- a/searchserver/README.md +++ b/searchserver/README.md @@ -3,7 +3,7 @@ Download MeiliSearch with: ``` -wget https://github.com/meilisearch/meilisearch/releases/download/v0.27.0/meilisearch-linux-amd64 +wget https://github.com/meilisearch/meilisearch/releases/download/v1.56.2/meilisearch-linux-amd64 chmod +x meilisearch-linux-amd64 ```