mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-18 10:40:03 +08:00
词条模糊匹配使用contains方法
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user