From 08b64338439a33a1b869ef0c77f09fd9b50bae2c Mon Sep 17 00:00:00 2001 From: Erdenezul Batmunkh Date: Sun, 20 May 2018 11:03:13 +0800 Subject: [PATCH] fix compare_indexes for text indexes #1751 --- mongoengine/document.py | 12 ++++++++++-- tests/document/class_methods.py | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mongoengine/document.py b/mongoengine/document.py index c948dac2..18c52d9d 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -967,8 +967,16 @@ class Document(BaseDocument): """ required = cls.list_indexes() - existing = [info['key'] - for info in cls._get_collection().index_information().values()] + + existing = [] + for info in cls._get_collection().index_information().values(): + if '_fts' in info['key'][0]: + index_type = info['key'][0][1] + text_index_fields = info.get('weights').keys() + existing.append( + [(key, index_type) for key in text_index_fields]) + else: + existing.append(info['key']) missing = [index for index in required if index not in existing] extra = [index for index in existing if index not in required] diff --git a/tests/document/class_methods.py b/tests/document/class_methods.py index 8701b4b2..3f052d45 100644 --- a/tests/document/class_methods.py +++ b/tests/document/class_methods.py @@ -192,7 +192,13 @@ class ClassMethodsTest(unittest.TestCase): class Doc(Document): a = StringField() - meta = { 'indexes': ['$a']} + b = StringField() + meta = {'indexes': [ + {'fields': ['$a', "$b"], + 'default_language': 'english', + 'weights': {'a': 10, 'b': 2} + } + ]} Doc.drop_collection() Doc.ensure_indexes()