关键字筛选题号 迁移到工具v3 完成

This commit is contained in:
weiye.wang 2024-04-16 06:52:24 +08:00
parent b1a9718222
commit e7c78714af
1 changed files with 23 additions and 2 deletions

View File

@ -973,7 +973,10 @@ def MatchConditioninMariaDB(condition_list):
"genre": ('problems','genre'), "genre": ('problems','genre'),
"ans": ('problems','ans'), "ans": ('problems','ans'),
"solution": ('problems','solution'), "solution": ('problems','solution'),
"remark": ('remarks','remark_content') "remark": ('remarks','remark_content'),
"same": ('same','ID','SAME_ID'),
"related": ('related','ID','RELATED_ID'),
"usages": ('usages','date','classname','diff')
} }
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")
mycursor = mydb.cursor() mycursor = mydb.cursor()
@ -982,9 +985,27 @@ def MatchConditioninMariaDB(condition_list):
for field,reverse,regexp in condition_list: for field,reverse,regexp in condition_list:
if not field in ["same","related","usages"]: if not field in ["same","related","usages"]:
table,column = corr_dict[field] table,column = corr_dict[field]
sql = f"SELECT ID FROM {table} WHERE {'NOT' if reverse else ''} {column} REGEXP '{regexp};" sql = f"SELECT ID FROM {table} WHERE {column} REGEXP '{regexp}';"
mycursor.execute(sql) mycursor.execute(sql)
newmatch = set([u[0] for u in mycursor.fetchall()]) newmatch = set([u[0] for u in mycursor.fetchall()])
elif field in ["same","related"]:
table,col0,col1 = corr_dict[field]
sql1 = f"SELECT {col1} FROM {table} WHERE {col0} REGEXP '{regexp}';"
mycursor.execute(sql1)
newmatch = set([u[0] for u in mycursor.fetchall()])
sql2 = f"SELECT {col0} FROM {table} WHERE {col1} REGEXP '{regexp}';"
mycursor.execute(sql2)
newmatch = newmatch | set([u[0] for u in mycursor.fetchall()])
elif field == "usages":
table,cols = corr_dict[field][0],corr_dict[field][1:]
newmatch = set([])
for i in range(len(cols)):
sql = f"SELECT ID FROM {table} WHERE {cols[i]} REGEXP '{regexp}';"
mycursor.execute(sql)
newmatch = newmatch | set([u[0] for u in mycursor.fetchall()])
if reverse:
match = match - newmatch
else:
match = match & newmatch match = match & newmatch
mydb.close() mydb.close()
return match return match