64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
![]() |
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
|
|||
|
}
|