Skip to content

Commit

Permalink
search_contacts方法添加模糊搜索参数
Browse files Browse the repository at this point in the history
  • Loading branch information
smallevilbeast committed Sep 6, 2022
1 parent 254123f commit 91d1257
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ntchat/core/wechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def search_contacts(self,
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、微信号、昵称和备注模糊搜索联系人
"""
Expand All @@ -217,8 +218,9 @@ def search_contacts(self,
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}"
Expand Down

0 comments on commit 91d1257

Please sign in to comment.