From 91d125722091bac59231cb4fdfa855d07e2c9407 Mon Sep 17 00:00:00 2001 From: evilbeast Date: Tue, 6 Sep 2022 11:31:16 +0800 Subject: [PATCH] =?UTF-8?q?search=5Fcontacts=E6=96=B9=E6=B3=95=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ntchat/core/wechat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ntchat/core/wechat.py b/ntchat/core/wechat.py index 722514b..1ab8b67 100644 --- a/ntchat/core/wechat.py +++ b/ntchat/core/wechat.py @@ -200,7 +200,8 @@ class WeChat: wxid: Union[None, str] = None, account: Union[None, str] = None, nickname: Union[None, str] = None, - remark: Union[None, str] = None): + remark: Union[None, str] = None, + fuzzy_search: bool = False): """ 根据wxid、微信号、昵称和备注模糊搜索联系人 """ @@ -217,8 +218,9 @@ class WeChat: return [] cond_pairs = [] + tag = '%' if fuzzy_search else '' for k, v in conds.items(): - cond_pairs.append(f"{k} like '%{v}%'") + cond_pairs.append(f"{k} like '{tag}{v}{tag}'") cond_str = " or ".join(cond_pairs) sql = f"select username from contact where {cond_str}"