Browse Source

Реализован поиск лиц по компетенциям #106

pull/118/head
Artur Galyamov 2 years ago
parent
commit
024759873c
  1. 17
      models/user/search.go
  2. 1
      routers/web/explore/competence.go

17
models/user/search.go

@ -17,6 +17,13 @@ import (
"xorm.io/xorm" "xorm.io/xorm"
) )
type SearchKind int64
const (
ByDescription SearchKind = iota
ByCompetence
)
// SearchUserOptions contains the options for searching // SearchUserOptions contains the options for searching
type SearchUserOptions struct { type SearchUserOptions struct {
db.ListOptions db.ListOptions
@ -28,6 +35,7 @@ type SearchUserOptions struct {
Visible []structs.VisibleType Visible []structs.VisibleType
Actor *User // The user doing the search Actor *User // The user doing the search
SearchByEmail bool // Search by email as well as username/full name SearchByEmail bool // Search by email as well as username/full name
Kind SearchKind
IsActive util.OptionalBool IsActive util.OptionalBool
IsAdmin util.OptionalBool IsAdmin util.OptionalBool
@ -53,8 +61,15 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
keywordCond := builder.Or( keywordCond := builder.Or(
builder.Like{"lower_name", lowerKeyword}, builder.Like{"lower_name", lowerKeyword},
builder.Like{"LOWER(full_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 { if opts.SearchByEmail {
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
} }

1
routers/web/explore/competence.go

@ -27,6 +27,7 @@ func Competences(ctx *context.Context) {
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
IsActive: util.OptionalBoolTrue, IsActive: util.OptionalBoolTrue,
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
Kind: user_model.ByCompetence,
}, tplExploreCompetences) }, tplExploreCompetences)
} }

Loading…
Cancel
Save