refactor: Adapt Meilisearch integration to v1.29.0 API

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-12 13:34:48 -07:00
parent c6f2880c25
commit 5bcca8e201
+10 -16
View File
@@ -29,24 +29,20 @@ def create_index():
json = dict(uid='qotnews', primaryKey='id') json = dict(uid='qotnews', primaryKey='id')
return meili_api(requests.post, 'indexes', json=json) return meili_api(requests.post, 'indexes', json=json)
def update_rankings(): def update_settings():
json = ['typo', 'words', 'proximity', 'date:desc', 'exactness'] json = {
return meili_api(requests.post, 'indexes/qotnews/settings/ranking-rules', json=json) 'rankingRules': ['typo', 'words', 'proximity', 'date:desc', 'exactness'],
'searchableAttributes': ['title', 'url', 'author'],
def update_attributes(): 'displayedAttributes': ['id', 'ref', 'source', 'author', 'author_link', 'score', 'date', 'title', 'link', 'url', 'num_comments'],
json = ['title', 'url', 'author'] }
r = meili_api(requests.post, 'indexes/qotnews/settings/searchable-attributes', json=json) return meili_api(requests.post, 'indexes/qotnews/settings', json=json)
json = ['id', 'ref', 'source', 'author', 'author_link', 'score', 'date', 'title', 'link', 'url', 'num_comments']
r = meili_api(requests.post, 'indexes/qotnews/settings/displayed-attributes', json=json)
return r
def init(): def init():
if not SEARCH_ENABLED: if not SEARCH_ENABLED:
logging.info('Search is not enabled, skipping init.') logging.info('Search is not enabled, skipping init.')
return return
print(create_index()) print(create_index())
update_rankings() update_settings()
update_attributes()
def put_story(story): def put_story(story):
if not SEARCH_ENABLED: return if not SEARCH_ENABLED: return
@@ -54,13 +50,11 @@ def put_story(story):
def search(q): def search(q):
if not SEARCH_ENABLED: return [] if not SEARCH_ENABLED: return []
params = dict(q=q, limit=settings.FEED_LENGTH) json = dict(q=q, limit=settings.FEED_LENGTH)
r = meili_api(requests.get, 'indexes/qotnews/search', params=params, parse_json=False) r = meili_api(requests.post, 'indexes/qotnews/search', json=json, parse_json=False)
return r return r
if __name__ == '__main__': if __name__ == '__main__':
init() init()
print(update_rankings())
print(search('facebook')) print(search('facebook'))