尝试重构collectionsQuery中的keywordAlt位
def countSubject(genres):
for keyword in genres:
keywordAlt = '%'+keyword+'%'
collectionsQuery = Collection.select().join(Subject).where(Subject.name ** keywordAlt, Subject.name != 'librivox', Subject.name != 'spoken', Subject.name != 'audiobook', Collection.downloads > 50)
if collectionsQuery.count() > 5:
print keyword, collectionsQuery.count()
我正在重构此代码段,并且想要首先删除keywordAlt位,并将文本包含在我的查询中。然而
collectionsQuery = Collection.select().join(Subject).where(Subject.name ** '%'+keyword+'%', Subject.name != 'librivox', Subject.name != 'spoken', Subject.name != 'audiobook', Collection.downloads > 50)
但是,使用第二种方法,它可以匹配所有内容。
collectionsQuery = Collection.select().join(Subject).where(Subject.name ** %keyword%, Subject.name != 'librivox', Subject.name != 'spoken', Subject.name != 'audiobook', Collection.downloads > 50)
这被解释为对“关键字”的通配符搜索
正确的语法是什么?
相关分类