feat:优化信息,完善es查询,完善网站首页公司信息查询
This commit is contained in:
106
app/service/es_manage.go
Normal file
106
app/service/es_manage.go
Normal file
@ -0,0 +1,106 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/serve/es"
|
||||
"SciencesServer/serve/logger"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ESManage struct {
|
||||
ID uint64 `json:"id"` // ID
|
||||
Identity int `json:"identity"` // 身份信息
|
||||
Industry string `json:"industry"` // 行业领域
|
||||
Title string `json:"title"` // 名称
|
||||
Keyword string `json:"keyword"` // 关键词
|
||||
Research string `json:"research"` // 研究方向
|
||||
}
|
||||
|
||||
type ESManageOption func(manage *ESManage)
|
||||
|
||||
func (this *ESManage) Index() string {
|
||||
if this.Identity > 0 {
|
||||
return fmt.Sprintf("es_manage_index_%d", this.Identity)
|
||||
}
|
||||
return "es_manage_index"
|
||||
}
|
||||
|
||||
func (this *ESManage) Create() error {
|
||||
if this.Industry != "" {
|
||||
this.Title = this.Industry + " - " + this.Title
|
||||
}
|
||||
_bytes, _ := json.Marshal(this)
|
||||
return es.Create(this.Index(), _bytes)
|
||||
}
|
||||
|
||||
func (this *ESManage) Search(page, pageSize int) (interface{}, error) {
|
||||
mustParams := make(map[string]interface{}, 0)
|
||||
shouldParams := make(map[string]interface{}, 0)
|
||||
|
||||
if this.Title != "" {
|
||||
shouldParams["title"] = this.Title
|
||||
}
|
||||
if this.Industry != "" {
|
||||
mustParams["title"] = this.Industry
|
||||
}
|
||||
if this.Keyword != "" {
|
||||
shouldParams["keyword"] = this.Keyword
|
||||
}
|
||||
if this.Research != "" {
|
||||
shouldParams["research"] = this.Research
|
||||
}
|
||||
out, err := es.Search(this, this.Index(), &es.SearchParams{
|
||||
MustParams: mustParams,
|
||||
ShouldParams: shouldParams,
|
||||
}, page, pageSize)
|
||||
|
||||
if err != nil {
|
||||
logger.ErrorF("查询ES信息错误:【%s】", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func WithManageID(id uint64) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.ID = id
|
||||
}
|
||||
}
|
||||
|
||||
func WithManageIdentity(identity int) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.Identity = identity
|
||||
}
|
||||
}
|
||||
|
||||
func WithManageTitle(title string) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.Title = title
|
||||
}
|
||||
}
|
||||
|
||||
func WithManageIndustry(industry string) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.Industry = industry
|
||||
}
|
||||
}
|
||||
|
||||
func WithManageKeyword(keyword string) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.Keyword = keyword
|
||||
}
|
||||
}
|
||||
|
||||
func WithManageResearch(research string) ESManageOption {
|
||||
return func(manage *ESManage) {
|
||||
manage.Research = research
|
||||
}
|
||||
}
|
||||
|
||||
func NewESManage(options ...ESManageOption) *ESManage {
|
||||
out := new(ESManage)
|
||||
|
||||
for _, option := range options {
|
||||
option(out)
|
||||
}
|
||||
return out
|
||||
}
|
Reference in New Issue
Block a user