mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 20:17:53 +08:00
Merge pull request #428 from XZFFF/develop
Develop:支持用户名和姓名的多条件模糊搜索,优化搜索结果的展示效果
This commit is contained in:
commit
11634d8c5b
@ -98,7 +98,8 @@ func (c *SearchController) User() {
|
||||
c.JsonResult(500, "项目不存在")
|
||||
}
|
||||
|
||||
members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId, 10, "%"+keyword+"%")
|
||||
//members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId, 10, "%"+keyword+"%")
|
||||
members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccountOrRealName(book.BookId, 10, "%"+keyword+"%")
|
||||
if err != nil {
|
||||
beego.Error("查询用户列表出错:" + err.Error())
|
||||
c.JsonResult(500, err.Error())
|
||||
@ -109,7 +110,7 @@ func (c *SearchController) User() {
|
||||
for _, member := range members {
|
||||
item := models.KeyValueItem{}
|
||||
item.Id = member.MemberId
|
||||
item.Text = member.Account
|
||||
item.Text = member.Account + "[" + member.RealName + "]"
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
|
@ -108,3 +108,17 @@ func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int,
|
||||
|
||||
return members, err
|
||||
}
|
||||
|
||||
// 根据姓名以及用户名模糊查询指定文档中不存在的用户列表
|
||||
func (m *MemberRelationshipResult) FindNotJoinUsersByAccountOrRealName(bookId, limit int, keyWord string) ([]*Member, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON rel.member_id = m.member_id AND rel.book_id = ? WHERE rel.relationship_id IS NULL AND (m.real_name LIKE ?) OR (m.account LIKE ?) LIMIT 0,?;"
|
||||
|
||||
var members []*Member
|
||||
|
||||
_, err := o.Raw(sql, bookId, keyWord,keyWord, limit).QueryRows(&members)
|
||||
|
||||
return members, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user