@@ -23,6 +23,7 @@ import (
23
23
"unicode/utf8"
24
24
25
25
"github.com/Unknwon/com"
26
+ "github.com/go-xorm/builder"
26
27
"github.com/go-xorm/xorm"
27
28
"github.com/nfnt/resize"
28
29
"golang.org/x/crypto/pbkdf2"
@@ -1235,27 +1236,28 @@ func SearchUserByName(opts *SearchUserOptions) (users []*User, _ int64, _ error)
1235
1236
opts .Page = 1
1236
1237
}
1237
1238
1238
- searchQuery := "%" + opts .Keyword + "%"
1239
1239
users = make ([]* User , 0 , opts .PageSize )
1240
+
1240
1241
// Append conditions
1241
- sess := x .
1242
- Where ("LOWER(lower_name) LIKE ?" , searchQuery ).
1243
- Or ("LOWER(full_name) LIKE ?" , searchQuery ).
1244
- And ("type = ?" , opts .Type )
1242
+ cond := builder .And (
1243
+ builder.Eq {"type" : opts .Type },
1244
+ builder .Or (
1245
+ builder.Like {"lower_name" , opts .Keyword },
1246
+ builder.Like {"LOWER(full_name)" , opts .Keyword },
1247
+ ),
1248
+ )
1245
1249
1246
- var countSess xorm.Session
1247
- countSess = * sess
1248
- count , err := countSess .Count (new (User ))
1250
+ count , err := x .Where (cond ).Count (new (User ))
1249
1251
if err != nil {
1250
1252
return nil , 0 , fmt .Errorf ("Count: %v" , err )
1251
1253
}
1252
1254
1255
+ sess := x .Where (cond ).
1256
+ Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize )
1253
1257
if len (opts .OrderBy ) > 0 {
1254
1258
sess .OrderBy (opts .OrderBy )
1255
1259
}
1256
- return users , count , sess .
1257
- Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize ).
1258
- Find (& users )
1260
+ return users , count , sess .Find (& users )
1259
1261
}
1260
1262
1261
1263
// ___________ .__ .__
0 commit comments