feat:优化信息,完善es查询,完善网站首页公司信息查询

This commit is contained in:
henry
2021-12-23 18:12:33 +08:00
parent eb2cfcb06b
commit b62ee9c3d9
4 changed files with 68 additions and 30 deletions

View File

@ -13,6 +13,7 @@ func (*ES) Create(c *gin.Context) {
ID uint64 `json:"id" form:"id"`
Identity int `json:"identity" form:"identity"`
Title string `json:"title" form:"title"`
Industry string `json:"industry" form:"industry"`
Keyword string `json:"keyword" form:"keyword"`
Research string `json:"research" form:"research"`
}{}
@ -20,12 +21,18 @@ func (*ES) Create(c *gin.Context) {
api.APIFailure(err.(error))(c)
return
}
manage := service.NewESManage(
service.WithManageID(form.ID),
service.WithManageIdentity(form.Identity),
service.WithManageTitle(form.Title),
service.WithManageKeyword(form.Keyword),
service.WithManageResearch(form.Research),
//manage := service.NewESManage(
// service.WithManageID(form.ID),
// service.WithManageIdentity(form.Identity),
// service.WithManageTitle(form.Title),
// service.WithManageKeyword(form.Keyword),
// service.WithManageResearch(form.Research),
//)
manage := service.NewESPatent(
service.WithPatentID(form.ID),
//service.WithManageIdentity(form.Identity),
service.WithPatentTitle(form.Title),
service.WithPatentIndustry(form.Industry),
)
api.APIResponse(manage.Create())(c)
}
@ -40,11 +47,15 @@ func (*ES) Search(c *gin.Context) {
api.APIFailure(err.(error))(c)
return
}
manage := service.NewESManage(service.WithManageIdentity(form.Identity),
service.WithManageTitle(form.Param),
service.WithManageIndustry(form.Industry),
service.WithManageKeyword(form.Param),
service.WithManageResearch(form.Param))
data, err := manage.Search(1, 1)
//manage := service.NewESManage(service.WithManageIdentity(form.Identity),
// service.WithManageTitle(form.Param),
// service.WithManageIndustry(form.Industry),
// service.WithManageKeyword(form.Param),
// service.WithManageResearch(form.Param))
manage := service.NewESPatent(
service.WithPatentTitle(form.Param),
service.WithPatentIndustry(form.Industry),
)
data, err := manage.Search(1, 10)
api.APIResponse(err, data)(c)
}

View File

@ -117,9 +117,6 @@ func (c *Search) Launch(identity int, param, industry string, page, pageSize int
ids := make([]uint64, 0)
for _, v := range out.([]*service.ESManage) {
if v.Identity != identity {
continue
}
ids = append(ids, v.ID)
}
handle, has := searchIdentityHandle[identity]

View File

@ -4,6 +4,7 @@ import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
"errors"
"fmt"
)
@ -28,27 +29,38 @@ type (
// Instance 查询信息
func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) {
// TODO缺少会员判断标准
mSysPatent := model.NewSysPatent()
// ES标准判定
s := service.NewESPatent(
service.WithPatentTitle(title),
service.WithPatentIndustry(industry),
)
out, err := s.Search(page, pageSize)
where := make([]*model2.ModelWhere, 0)
list := make([]*PatentInfo, 0)
if title != "" {
where = append(where, model2.NewWhereLike("p.title", title))
}
if industry != "" {
where = append(where, model2.NewWhereCondition("c.industry_detail", "LIKE",
"%"+fmt.Sprintf(`"%v`, industry)+"%"))
}
var count int64
out, err := mSysPatent.Patent(page, pageSize, &count, where...)
fmt.Println(out)
if err != nil {
return nil, err
} else if out == nil {
return &controller.ReturnPages{Data: list, Count: count}, nil
}
list := make([]*PatentInfo, 0)
mSysPatent := model.NewSysPatent()
for _, v := range out {
ids := make([]uint64, 0)
for _, v := range out.([]interface{}) {
val := v.(*service.ESPatent)
ids = append(ids, val.ID)
}
ret := make([]*model.SysPatentInfo, 0)
if ret, err = mSysPatent.Patent(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil {
return nil, err
}
for _, v := range ret {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(),
SysPatentInfo: v,

View File

@ -3,7 +3,9 @@ package service
import (
"SciencesServer/serve/es"
"SciencesServer/serve/logger"
"SciencesServer/utils"
"encoding/json"
"fmt"
)
type ESPatent struct {
@ -19,14 +21,30 @@ func (this *ESPatent) Index() string {
}
func (this *ESPatent) Create() error {
if this.Industry != "" {
this.Title = this.Industry + " - " + this.Title
}
_bytes, _ := json.Marshal(this)
return es.Create(this.Index(), _bytes)
}
func (this *ESPatent) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) {
func (this *ESPatent) Search(page, pageSize int) (interface{}, error) {
mustParams := make(map[string]interface{}, 0)
shouldParams := make(map[string]interface{}, 0)
fmt.Println(utils.AnyToJSON(this))
if this.Title != "" {
shouldParams["title"] = this.Title
}
if this.Industry != "" {
mustParams["title"] = this.Industry
}
fmt.Println(mustParams)
fmt.Println(shouldParams)
out, err := es.Search(this, this.Index(), &es.SearchParams{
MustParams: nil,
ShouldParams: params,
MustParams: mustParams,
ShouldParams: shouldParams,
}, page, pageSize)
if err != nil {