Python 使用按最大匹配排序的NDB查询
我有一个带有查询的模型:Python 使用按最大匹配排序的NDB查询,python,google-app-engine,app-engine-ndb,Python,Google App Engine,App Engine Ndb,我有一个带有查询的模型: class Words (ndb.Model): word = ndb.StringProperty () key = ndb.KeyProperty ("OtherModel") count = ndb.IntegerProperty () @classmethod def query_words (cls, words): return cls.query (cls.word.IN (words)).ord
class Words (ndb.Model):
word = ndb.StringProperty ()
key = ndb.KeyProperty ("OtherModel")
count = ndb.IntegerProperty ()
@classmethod
def query_words (cls, words):
return cls.query (cls.word.IN (words)).order (cls.count, cls.key)
这不是我真正想要的。我希望能够按照匹配的数量进行排序,即密钥实际出现在结果集中的次数;如果列表中有四个单词,并且每个单词都有一个关键结果,那么我想先看看
该模型本质上是模型中单词的频率表,在我的示例中,它由key OtherModel表示
TIA。数据存储查询无法实现您的提问。顺序只能由预定义的字典确定。您可能应该考虑使用cloudsql,或者在内存中重新排序。谢谢Tim。在记忆中是这样的。