def _create_text_index(self, fields=None):
"""Create a text index for the database collection.
Takes a list of fields and creates a text index based on the
Engine's schema, if it has one. Otherwise, creates a text index
for any field that contains string content.
"""
collection = self._collection
index_name = 'TextIndex'
if fields:
index = []
for field in self.schema:
if field.field_type in self.TEXT_INDEXES:
index.append((field.field_name, pymongo.TEXT))
return collection.create_index(index, background=True,
name=index_name)
else:
return collection.create_index([('$**', pymongo.TEXT)],
name=index_name)
评论列表
文章目录