feat:完成首页搜索功能
This commit is contained in:
70
app/api/website/controller/search/expert.go
Normal file
70
app/api/website/controller/search/expert.go
Normal file
@ -0,0 +1,70 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
config2 "SciencesServer/config"
|
||||
)
|
||||
|
||||
type (
|
||||
// ExpertInfo 专家信息
|
||||
ExpertInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageExpertInfo
|
||||
Industrys []string `json:"industrys"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
)
|
||||
|
||||
// searchExpert 专家搜索
|
||||
func searchExpert(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
|
||||
manage := service.NewESManage(
|
||||
service.WithManageIdentity(config.TenantUserIdentityForExpert),
|
||||
service.WithManageTitle(keyword),
|
||||
service.WithManageKeyword(keyword),
|
||||
service.WithManageResearch(keyword),
|
||||
)
|
||||
if industry != "" {
|
||||
service.WithManageIndustry(industry)(manage)
|
||||
}
|
||||
out, err := manage.Search(page, pageSize, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]uint64, 0)
|
||||
|
||||
for _, v := range out.([]interface{}) {
|
||||
val := v.(*service.ESManage)
|
||||
ids = append(ids, val.ID)
|
||||
}
|
||||
if len(ids) <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
experts := make([]*model.ManageExpertInfo, 0)
|
||||
|
||||
if experts, err = mManageExpert.Expert(3, model2.NewWhereIn("e.id", ids)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ExpertInfo, 0)
|
||||
|
||||
for _, v := range experts {
|
||||
_industrys := make([]string, 0)
|
||||
|
||||
for _, v := range v.GetIndustryAttribute() {
|
||||
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
|
||||
}
|
||||
|
||||
v.Image.Image = v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
|
||||
|
||||
list = append(list, &ExpertInfo{
|
||||
ID: v.GetEncodeID(), ManageExpertInfo: v,
|
||||
Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
Reference in New Issue
Block a user