mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-06 00:16:53 +08:00
support sqlite es highlight
This commit is contained in:
@@ -110,7 +110,6 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model
|
||||
if req.Match.Using != "" {
|
||||
queryList = append(queryList, elastic.NewMatchQuery("using", req.Match.Using))
|
||||
}
|
||||
|
||||
if len(filterProcessName) != 0 { // 过滤进程名
|
||||
shouldQueryList := []elastic.Query{}
|
||||
for _, fpn := range filterProcessName {
|
||||
@@ -123,7 +122,7 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model
|
||||
}
|
||||
|
||||
result := model.LogResp{}
|
||||
resp, err := search.Query(elastic.NewBoolQuery().Must(queryList...)).Do(context.TODO())
|
||||
resp, err := search.Query(elastic.NewBoolQuery().Must(queryList...)).Highlight(elastic.NewHighlight().Field("log").PreTags("\033[43m").PostTags("\033[0m")).Do(context.TODO())
|
||||
if err != nil {
|
||||
log.Logger.Errorw("es查询失败", "err", err, "reason", resp.Error.Reason)
|
||||
return result
|
||||
@@ -134,6 +133,9 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model
|
||||
if v.Source != nil {
|
||||
var data model.ProcessLog
|
||||
if err := json.Unmarshal(v.Source, &data); err == nil {
|
||||
if len(v.Highlight) > 0 && len(v.Highlight["log"]) > 0 {
|
||||
data.Log = v.Highlight["log"][0]
|
||||
}
|
||||
result.Data = append(result.Data, &data)
|
||||
} else {
|
||||
log.Logger.Errorw("JSON 解码失败", "err", err)
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/config"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
@@ -37,6 +39,11 @@ var LogSqlite = new(logSqlite)
|
||||
func (l *logSqlite) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp {
|
||||
req.FilterName = filterProcessName
|
||||
data, total := repository.LogRepository.SearchLog(req)
|
||||
if req.Match.Log != "" {
|
||||
for i := range data {
|
||||
data[i].Log = strings.ReplaceAll(data[i].Log, req.Match.Log, "\033[43m"+req.Match.Log+"\033[0m")
|
||||
}
|
||||
}
|
||||
return model.LogResp{
|
||||
Data: data,
|
||||
Total: total,
|
||||
|
Reference in New Issue
Block a user