def initialize_indexes(database):
"""Ensure the necessary indexes exist."""
submissions = database['submissions']
comments = database['comments']
index_id = pymongo.IndexModel('reddit_id')
index_created = pymongo.IndexModel([('created', pymongo.DESCENDING)])
index_text_title_and_body = pymongo.IndexModel([('title', pymongo.TEXT),
('body', pymongo.TEXT)])
index_text_body = pymongo.IndexModel([('body', pymongo.TEXT)])
submissions.create_indexes([index_id,
index_created,
index_text_title_and_body])
comments.create_indexes([index_id,
index_created,
index_text_body])
评论列表
文章目录