From 024759873c966245c33b1530f7989b07068d675e Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 18:57:25 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=20=D0=BF=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D1=8F=D0=BC=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/user/search.go | 17 ++++++++++++++++- routers/web/explore/competence.go | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) 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) }