静的メソッドを親クラスにフルテキスト検索を実行しようとしているときにエラー、およびフラスコ/ Mongoengine:私はItemクラスを作成しました
class Item(db.Document):
name = db.StringField()
slug = db.StringField()
description = db.StringField()
content = db.StringField()
start_time = db.DateTimeField()
end_time = db.DateTimeField()
@staticmethod
def search_static(keywords):
return Item.objects.search_text(keywords).order_by('$text_score')
@classmethod
def search_class(cls,keywords):
return cls.objects.search_text(keywords).order_by('$text_score')
meta = {
'allow_inheritance' : True,
'indexes' : [
{
'fields': ['$name','$slug','$description','$content'],
'default_language':'french',
'weights': {'name': 10, 'slug': 10 , 'description': 5, 'content': 5}
}
]
}
class Item1(Item):
item_type = db.ReferenceField('T1')
class Item2(Item):
item_type = db.ReferenceField('T2')
class T1(db.Document):
name = db.StringField()
class T2(db.Document):
name = db.StringField()
次以下のように2つのサブクラスアイテム1とアイテム2、私が作成しました私はクラスメソッド
>>> Item1.search_class("dog")
[<Item1: Item1 object>, <Item1: Item1 object>]
>>> Item1.search_class("viper")
[<Item1: Item1 object>]
>>> Item2.search_class("viper")
[<Item2: Item2 object>]
>>> Item2.search_class("tiger")
[]
>>>
にテストしていたときに、いくつかの項目
Results in mongo shell of following commands db.item.find()/db.t1.find()/db.t2.find()
すべてが大丈夫です10
しかし、私は(一度にすべてのサブクラスで検索するために)静的メソッドを使用する場合、私はこのMongoのエラーを持っている:
>>> Item.search_static("tiger")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/venv/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 58, in __repr__
self._populate_cache()
File "/venv/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 92, in _populate_cache
self._result_cache.append(self.next())
File "/venv/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1407, in next
raw_doc = self._cursor.next()
File "/venv/lib/python2.7/site-packages/pymongo/cursor.py", line 1090, in next
if len(self.__data) or self._refresh():
File "/venv/lib/python2.7/site-packages/pymongo/cursor.py", line 1012, in _refresh
self.__read_concern))
File "/venv/lib/python2.7/site-packages/pymongo/cursor.py", line 905, in __send_message
helpers._check_command_response(doc['data'][0])
File "/venv/lib/python2.7/site-packages/pymongo/helpers.py", line 196, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: error processing query: ns=archives_flask.itemTree: $and
_cls $in [ "Item" "Item.Item1" "Item.Item2" ]
TEXT : query=tiger, language=french, caseSensitive=0, diacriticSensitive=0, tag=NULL
Sort: { _text_score: { $meta: "textScore" } }
Proj: { _text_score: { $meta: "textScore" } }
planner returned error: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given for all prefix fields?)
>>>
あなたが任意のアイデアやヒントを支援してもらえますか?