def search(keywords, lang):
formated_keywords = [ unidecode.unidecode(keyword).lower() for keyword in keywords ]
with model.laima_db.transaction():
query = (model.CardText
.select(model.CardText, model.CardData)
.join(model.CardData)
.switch(model.CardText)
.where(model.CardText.lang == lang)
.join(model.CardTextTag)
.join(model.Tag)
.where(model.Tag.name << formated_keywords)
.group_by(model.CardText)
.having(fn.Count(model.Tag.id) == len(keywords))
.order_by(model.CardText.name))
if query.exists():
count = query.count()
cards = [ card for card in query ]
return cards, count
else:
return [], 0
评论列表
文章目录