Upgrade meilisearch to v1.56.2
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+8
-8
@@ -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__':
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user