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

This commit is contained in:
henry
2021-12-23 17:43:27 +08:00
parent 741138b3ea
commit eb2cfcb06b
18 changed files with 441 additions and 93 deletions

View File

@ -1,62 +0,0 @@
package service
import (
"SciencesServer/serve/es"
"encoding/json"
)
type Manage struct {
ID uint64 `json:"id"` // ID
Identity int `json:"identity"` // 身份信息
Title string `json:"title"` // 名称
Keyword string `json:"keyword"` // 关键词
Research string `json:"research"` // 研究方向
}
type ManageOption func(manage *Manage)
func (c *Manage) Index() string {
return "es_manage_index"
}
func (this *Manage) Create() error {
_bytes, _ := json.Marshal(this)
return es.Create(this.Index(), _bytes)
}
func (this *Manage) Search(page, pageSize int, condition map[string]interface{}) (interface{}, error) {
return es.Search(this, this.Index(), condition, page, pageSize)
}
func WithManageID(id uint64) ManageOption {
return func(manage *Manage) {
manage.ID = id
}
}
func WithManageTitle(title string) ManageOption {
return func(manage *Manage) {
manage.Title = title
}
}
func WithManageKeyword(keyword string) ManageOption {
return func(manage *Manage) {
manage.Keyword = keyword
}
}
func WithManageResearch(research string) ManageOption {
return func(manage *Manage) {
manage.Research = research
}
}
func NewManage(options ...ManageOption) *Manage {
out := new(Manage)
for _, option := range options {
option(out)
}
return out
}

106
app/service/es_manage.go Normal file
View 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
}

63
app/service/es_patent.go Normal file
View File

@ -0,0 +1,63 @@
package service
import (
"SciencesServer/serve/es"
"SciencesServer/serve/logger"
"encoding/json"
)
type ESPatent struct {
ID uint64 `json:"id"`
Title string `json:"title"`
Industry string `json:"industry"` // 行业领域
}
type ESPatentOption func(patent *ESPatent)
func (this *ESPatent) Index() string {
return "es_patent_index"
}
func (this *ESPatent) Create() error {
_bytes, _ := json.Marshal(this)
return es.Create(this.Index(), _bytes)
}
func (this *ESPatent) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) {
out, err := es.Search(this, this.Index(), &es.SearchParams{
MustParams: nil,
ShouldParams: params,
}, page, pageSize)
if err != nil {
logger.ErrorF("查询ES信息错误【%s】", err)
}
return out, nil
}
func WithPatentID(id uint64) ESPatentOption {
return func(patent *ESPatent) {
patent.ID = id
}
}
func WithPatentTitle(title string) ESPatentOption {
return func(patent *ESPatent) {
patent.Title = title
}
}
func WithPatentIndustry(industry string) ESPatentOption {
return func(patent *ESPatent) {
patent.Industry = industry
}
}
func NewESPatent(options ...ESPatentOption) *ESPatent {
out := new(ESPatent)
for _, v := range options {
v(out)
}
return out
}