词条模糊匹配使用contains方法

This commit is contained in:
HibiKier
2022-08-21 18:32:24 +08:00
parent d183903917
commit 2051e8183c
3 changed files with 12 additions and 10 deletions
+8 -6
View File
@@ -236,17 +236,19 @@ class WordBank(db.Model):
# 完全匹配
if await query.where(cls.problem == problem).gino.first():
return query.where(cls.problem == problem)
# 模糊匹配
if await query.where(cls.problem.contains(problem)).gino.first():
return query.where(cls.problem.contains(problem))
# 正则匹配
if await db.first(
db.text(sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;")
):
return sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;"
# 模糊匹配
if await db.first(
db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;")
):
return sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;"
return None
# if await db.first(
# db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;")
# ):
# return sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;"
# return None
@classmethod
async def get_answer(