feat:优化es查询规则

This commit is contained in:
henry
2021-12-24 09:13:16 +08:00
parent b62ee9c3d9
commit ebf74435ef
5 changed files with 39 additions and 55 deletions

View File

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

View File

@ -34,15 +34,15 @@ func (this *ESManage) Create() error {
}
func (this *ESManage) Search(page, pageSize int) (interface{}, error) {
mustParams := make(map[string]interface{}, 0)
termParams := make(map[string]interface{}, 0)
shouldParams := make(map[string]interface{}, 0)
if this.Industry != "" {
termParams["industry"] = this.Industry
}
if this.Title != "" {
shouldParams["title"] = this.Title
}
if this.Industry != "" {
mustParams["title"] = this.Industry
}
if this.Keyword != "" {
shouldParams["keyword"] = this.Keyword
}
@ -50,7 +50,7 @@ func (this *ESManage) Search(page, pageSize int) (interface{}, error) {
shouldParams["research"] = this.Research
}
out, err := es.Search(this, this.Index(), &es.SearchParams{
MustParams: mustParams,
TermParams: termParams,
ShouldParams: shouldParams,
}, page, pageSize)

View File

@ -21,30 +21,25 @@ 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) (interface{}, error) {
termParams := make(map[string]interface{}, 0)
mustParams := make(map[string]interface{}, 0)
shouldParams := make(map[string]interface{}, 0)
fmt.Println(utils.AnyToJSON(this))
if this.Title != "" {
shouldParams["title"] = this.Title
mustParams["title"] = this.Title
}
if this.Industry != "" {
mustParams["title"] = this.Industry
termParams["title"] = this.Industry
}
fmt.Println(mustParams)
fmt.Println(shouldParams)
out, err := es.Search(this, this.Index(), &es.SearchParams{
MustParams: mustParams,
ShouldParams: shouldParams,
TermParams: termParams,
MustParams: mustParams,
}, page, pageSize)
if err != nil {