diff --git a/models/user/search.go b/models/user/search.go index 453d09558d..f33039582f 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -17,6 +17,13 @@ import ( "xorm.io/xorm" ) +type SearchKind int64 + +const ( + ByDescription SearchKind = iota + ByCompetence +) + // SearchUserOptions contains the options for searching type SearchUserOptions struct { db.ListOptions @@ -28,6 +35,7 @@ type SearchUserOptions struct { Visible []structs.VisibleType Actor *User // The user doing the search SearchByEmail bool // Search by email as well as username/full name + Kind SearchKind IsActive util.OptionalBool IsAdmin util.OptionalBool @@ -53,8 +61,15 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { keywordCond := builder.Or( builder.Like{"lower_name", lowerKeyword}, builder.Like{"LOWER(full_name)", lowerKeyword}, - builder.Like{"LOWER(description)", lowerKeyword}, ) + switch opts.Kind { + case ByDescription: + keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) + case ByCompetence: + keywordCond = builder.Or(builder.Like{"LOWER(competences)", lowerKeyword}) + default: + keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) + } if opts.SearchByEmail { keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) } diff --git a/routers/web/explore/competence.go b/routers/web/explore/competence.go index ccd7bf64f2..20eaaa38c5 100644 --- a/routers/web/explore/competence.go +++ b/routers/web/explore/competence.go @@ -27,6 +27,7 @@ func Competences(ctx *context.Context) { ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, IsActive: util.OptionalBoolTrue, Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Kind: user_model.ByCompetence, }, tplExploreCompetences) }