✨ finish es highlight
This commit is contained in:
parent
5ff73e318e
commit
45ba7ea003
6
app/global/consts/style.go
Normal file
6
app/global/consts/style.go
Normal file
@ -0,0 +1,6 @@
|
||||
package consts
|
||||
|
||||
const (
|
||||
PreTags string = `<span style=\"color: #0062FF;\">`
|
||||
PostTags string = "</span>"
|
||||
)
|
@ -2,6 +2,7 @@ package model_es
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"catface/app/global/consts"
|
||||
"catface/app/global/variable"
|
||||
"catface/app/model"
|
||||
"catface/app/utils/data_bind"
|
||||
@ -89,8 +90,8 @@ func (a *Animal) QueryDocumentsMatchAll(query string, num int) ([]Animal, error)
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"pre_tags": ["<em>"],
|
||||
"post_tags": ["</em>"],
|
||||
"pre_tags": ["%v"],
|
||||
"post_tags": ["%v"],
|
||||
"fields": {
|
||||
"name": {},
|
||||
"nick_names": {
|
||||
@ -102,7 +103,7 @@ func (a *Animal) QueryDocumentsMatchAll(query string, num int) ([]Animal, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, num, query, query, query)
|
||||
}`, num, query, query, query, consts.PreTags, consts.PostTags)
|
||||
|
||||
hits, err := model_handler.SearchRequest(body, a.IndexName())
|
||||
if err != nil {
|
||||
|
@ -2,6 +2,7 @@ package model_es
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"catface/app/global/consts"
|
||||
"catface/app/global/variable"
|
||||
"catface/app/model"
|
||||
"catface/app/utils/data_bind"
|
||||
@ -144,8 +145,8 @@ func (e *Encounter) QueryDocumentsMatchAll(query string, num int) ([]Encounter,
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"pre_tags": ["<em>"],
|
||||
"post_tags": ["</em>"],
|
||||
"pre_tags": ["%v"],
|
||||
"post_tags": ["%v"],
|
||||
"fields": {
|
||||
"title": {},
|
||||
"content": {
|
||||
@ -157,7 +158,7 @@ func (e *Encounter) QueryDocumentsMatchAll(query string, num int) ([]Encounter,
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, num, query, query, query)
|
||||
}`, num, query, query, query, consts.PreTags, consts.PostTags)
|
||||
|
||||
hits, err := model_handler.SearchRequest(body, e.IndexName())
|
||||
if err != nil {
|
||||
@ -173,6 +174,10 @@ func (e *Encounter) QueryDocumentsMatchAll(query string, num int) ([]Encounter,
|
||||
continue
|
||||
}
|
||||
|
||||
if len(encounter.Content) > 15*3 {
|
||||
encounter.Content = encounter.Content[:15*3] + "..."
|
||||
}
|
||||
|
||||
encounters = append(encounters, encounter)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package model_es
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"catface/app/global/consts"
|
||||
"catface/app/global/variable"
|
||||
"catface/app/utils/data_bind"
|
||||
"catface/app/utils/model_handler"
|
||||
@ -165,8 +166,8 @@ func (k *Knowledge) QueryDocumentsMatchAll(query string, num int) ([]Knowledge,
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"pre_tags": ["<em>"],
|
||||
"post_tags": ["</em>"],
|
||||
"pre_tags": ["%v"],
|
||||
"post_tags": ["%v"],
|
||||
"fields": {
|
||||
"title": {},
|
||||
"content": {
|
||||
@ -174,7 +175,7 @@ func (k *Knowledge) QueryDocumentsMatchAll(query string, num int) ([]Knowledge,
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, num, query, query) // TODO dirs 我还没想好如何处理
|
||||
}`, num, query, query, consts.PreTags, consts.PostTags) // TODO dirs 我还没想好如何处理
|
||||
// 创建请求
|
||||
req := esapi.SearchRequest{
|
||||
Index: []string{k.IndexName()},
|
||||
|
@ -138,7 +138,7 @@ func (a *AnimalsCurd) MatchAll(query string, num int) (tmp []model.Animal) {
|
||||
}
|
||||
|
||||
// STAGE 2. MySQL 补充信息
|
||||
animalsFromSQL := model.CreateAnimalFactory("").ShowByIDs(ids, "id", "avatar")
|
||||
animalsFromSQL := model.CreateAnimalFactory("").ShowByIDs(ids, "id", "avatar", "status", "department")
|
||||
|
||||
// 3. 合并信息
|
||||
for _, animalFromES := range animalsFromES {
|
||||
|
Loading…
x
Reference in New Issue
Block a user