|
@@ -5,6 +5,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"eta/eta_mobile/models/data_manage"
|
|
|
+ "eta/eta_mobile/models/data_manage/excel"
|
|
|
"eta/eta_mobile/utils"
|
|
|
"fmt"
|
|
|
"github.com/olivere/elastic/v7"
|
|
@@ -827,6 +828,14 @@ func searchEdbInfoData(indexName string, mustMap, mustNotMap []interface{}, shou
|
|
|
|
|
|
queryMap["from"] = from
|
|
|
queryMap["size"] = size
|
|
|
+ queryMap["highlight"] = map[string]interface{}{
|
|
|
+ "fields": map[string]interface{}{
|
|
|
+ "EdbName": map[string]interface{}{},
|
|
|
+ },
|
|
|
+ "pre_tags": "<span style=\"color:#0052D9\">",
|
|
|
+ "post_tags": "</span>",
|
|
|
+ }
|
|
|
+
|
|
|
jsonBytes, _ := json.Marshal(queryMap)
|
|
|
fmt.Println(string(jsonBytes))
|
|
|
|
|
@@ -884,7 +893,11 @@ func searchEdbInfoData(indexName string, mustMap, mustNotMap []interface{}, shou
|
|
|
edbInfoItem.EdbCode = v.Highlight["EdbCode"][0]
|
|
|
}
|
|
|
if len(v.Highlight["EdbName"]) > 0 {
|
|
|
- edbInfoItem.EdbCode = v.Highlight["EdbName"][0]
|
|
|
+ // 搜索结果高亮用新字段,原EdbName直接高亮展示上会有点影响
|
|
|
+ edbInfoItem.SearchText = v.Highlight["EdbName"][0]
|
|
|
+ //edbInfoItem.EdbName = v.Highlight["EdbName"][0]
|
|
|
+ } else {
|
|
|
+ edbInfoItem.SearchText = edbInfoItem.EdbName
|
|
|
}
|
|
|
list = append(list, edbInfoItem)
|
|
|
searchMap[v.Id] = v.Id
|
|
@@ -1224,8 +1237,8 @@ func EsDeleteDataV2(indexName, docId string) (err error) {
|
|
|
}
|
|
|
|
|
|
// SearchChartInfoData 查询es中的图表数据
|
|
|
-func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList []int, noPermissionChartIdList []int, from, size int) (list []*data_manage.ChartInfo, total int64, err error) {
|
|
|
- list = make([]*data_manage.ChartInfo, 0)
|
|
|
+func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList []int, noPermissionChartIdList []int, from, size int) (list []*data_manage.ChartInfoMore, total int64, err error) {
|
|
|
+ list = make([]*data_manage.ChartInfoMore, 0)
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
fmt.Println("EsAddOrEditData Err:", err.Error())
|
|
@@ -1362,6 +1375,14 @@ func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList
|
|
|
// 分页查询
|
|
|
queryMap["from"] = from
|
|
|
queryMap["size"] = size
|
|
|
+ queryMap["highlight"] = map[string]interface{}{
|
|
|
+ "fields": map[string]interface{}{
|
|
|
+ keywordNameKey: map[string]interface{}{},
|
|
|
+ },
|
|
|
+ "pre_tags": "<span style=\"color:#0052D9\">",
|
|
|
+ "post_tags": "</span>",
|
|
|
+ }
|
|
|
+
|
|
|
jsonBytes, _ := json.Marshal(queryMap)
|
|
|
fmt.Println(string(jsonBytes))
|
|
|
|
|
@@ -1393,15 +1414,18 @@ func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList
|
|
|
fmt.Println("movieJson err:", err)
|
|
|
return
|
|
|
}
|
|
|
- chartInfoItem := new(data_manage.ChartInfo)
|
|
|
+ chartInfoItem := new(data_manage.ChartInfoMore)
|
|
|
tmpErr = json.Unmarshal(itemJson, &chartInfoItem)
|
|
|
if err != nil {
|
|
|
fmt.Println("json.Unmarshal chartInfoJson err:", err)
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- if len(v.Highlight["ChartName"]) > 0 {
|
|
|
- chartInfoItem.ChartName = v.Highlight["ChartName"][0]
|
|
|
+ if len(v.Highlight[keywordNameKey]) > 0 {
|
|
|
+ //chartInfoItem.ChartName = v.Highlight["ChartName"][0]
|
|
|
+ chartInfoItem.SearchText = v.Highlight[keywordNameKey][0]
|
|
|
+ } else {
|
|
|
+ chartInfoItem.SearchText = chartInfoItem.ChartName
|
|
|
}
|
|
|
list = append(list, chartInfoItem)
|
|
|
searchMap[v.Id] = v.Id
|
|
@@ -1574,6 +1598,14 @@ func SearchMyChartInfoData(indexName, keywordStr string, adminId int, noPermissi
|
|
|
// 分页查询
|
|
|
queryMap["from"] = from
|
|
|
queryMap["size"] = size
|
|
|
+ queryMap["highlight"] = map[string]interface{}{
|
|
|
+ "fields": map[string]interface{}{
|
|
|
+ keywordNameKey: map[string]interface{}{},
|
|
|
+ },
|
|
|
+ "pre_tags": "<span style=\"color:#0052D9\">",
|
|
|
+ "post_tags": "</span>",
|
|
|
+ }
|
|
|
+
|
|
|
jsonBytes, _ := json.Marshal(queryMap)
|
|
|
fmt.Println(string(jsonBytes))
|
|
|
|
|
@@ -1612,8 +1644,11 @@ func SearchMyChartInfoData(indexName, keywordStr string, adminId int, noPermissi
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- if len(v.Highlight["ChartName"]) > 0 {
|
|
|
- chartInfoItem.ChartName = v.Highlight["ChartName"][0]
|
|
|
+ if len(v.Highlight[keywordNameKey]) > 0 {
|
|
|
+ //chartInfoItem.ChartName = v.Highlight["ChartName"][0]
|
|
|
+ chartInfoItem.SearchText = v.Highlight[keywordNameKey][0]
|
|
|
+ } else {
|
|
|
+ chartInfoItem.SearchText = chartInfoItem.ChartName
|
|
|
}
|
|
|
list = append(list, chartInfoItem)
|
|
|
searchMap[v.Id] = v.Id
|
|
@@ -1850,3 +1885,158 @@ func SearchEdbInfoDataByAdminId(indexName, keywordStr string, from, size, filter
|
|
|
|
|
|
return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
|
|
|
}
|
|
|
+
|
|
|
+// SearchExcelInfoData 查询es中的表格
|
|
|
+func SearchExcelInfoData(indexName, keyword string, source, adminId int, queryIds, exceptIds []int, from, size int) (total int64, list []*excel.SearchExcelInfo, err error) {
|
|
|
+ list = make([]*excel.SearchExcelInfo, 0)
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := fmt.Sprintf("SearchExcelInfoData err: %v", err)
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ client := utils.EsClient
|
|
|
+
|
|
|
+ mustMap := make([]interface{}, 0)
|
|
|
+ mustNotMap := make([]interface{}, 0)
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "term": map[string]interface{}{
|
|
|
+ "IsDelete": 0,
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ // 表格名称
|
|
|
+ shouldMap := make(map[string]interface{}, 0)
|
|
|
+ if keyword != "" {
|
|
|
+ shouldMap["should"] = []interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "match": map[string]interface{}{
|
|
|
+ "ExcelName": keyword,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ //shouldMap := map[string]interface{}{
|
|
|
+ // "should": []interface{}{
|
|
|
+ // map[string]interface{}{
|
|
|
+ // "match": map[string]interface{}{
|
|
|
+ // "ExcelName": keyword,
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表格来源
|
|
|
+ if source > 0 {
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "term": map[string]interface{}{
|
|
|
+ "Source": source,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建人
|
|
|
+ if adminId > 0 {
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "term": map[string]interface{}{
|
|
|
+ "SysUserId": adminId,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询和排除的表格IDs
|
|
|
+ if len(queryIds) > 0 {
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "terms": map[string]interface{}{
|
|
|
+ "ExcelInfoId": queryIds,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if len(exceptIds) > 0 {
|
|
|
+ mustNotMap = append(mustNotMap, map[string]interface{}{
|
|
|
+ "terms": map[string]interface{}{
|
|
|
+ "ExcelInfoId": exceptIds,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关键字匹配
|
|
|
+ mustMap = append(mustMap, map[string]interface{}{
|
|
|
+ "bool": shouldMap,
|
|
|
+ })
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "query": map[string]interface{}{
|
|
|
+ "bool": map[string]interface{}{
|
|
|
+ "must": mustMap,
|
|
|
+ "must_not": mustNotMap,
|
|
|
+ //"should": shouldMap,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ //jsonBytes, _ := json.Marshal(queryMap)
|
|
|
+ //fmt.Println(string(jsonBytes))
|
|
|
+
|
|
|
+ // 根据条件数量统计
|
|
|
+ requestTotalHits := client.Count(indexName).BodyJson(queryMap)
|
|
|
+ t, e := requestTotalHits.Do(context.Background())
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("total hits err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total = t
|
|
|
+
|
|
|
+ // 表格名称高亮,分页
|
|
|
+ highlightKeyName := "ExcelName"
|
|
|
+ queryMap["highlight"] = map[string]interface{}{
|
|
|
+ "fields": map[string]interface{}{
|
|
|
+ highlightKeyName: map[string]interface{}{},
|
|
|
+ },
|
|
|
+ "pre_tags": "<span style=\"color:#0052D9\">",
|
|
|
+ "post_tags": "</span>",
|
|
|
+ }
|
|
|
+ queryMap["from"] = from
|
|
|
+ queryMap["size"] = size
|
|
|
+
|
|
|
+ //jsonBytes, _ := json.Marshal(queryMap)
|
|
|
+ //fmt.Println(string(jsonBytes))
|
|
|
+
|
|
|
+ request := client.Search(indexName).Source(queryMap)
|
|
|
+ searchResp, e := request.Do(context.Background())
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("search do err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //fmt.Println(searchResp)
|
|
|
+ if searchResp.Status != 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if searchResp.Hits == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ searchMap := make(map[string]string)
|
|
|
+ for _, v := range searchResp.Hits.Hits {
|
|
|
+ if _, ok := searchMap[v.Id]; ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ j, e := v.Source.MarshalJSON()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("hits json err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(excel.SearchExcelInfo)
|
|
|
+ if e = json.Unmarshal(j, &item); e != nil {
|
|
|
+ err = fmt.Errorf("hits json unmarshal err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v.Highlight[highlightKeyName]) > 0 {
|
|
|
+ item.SearchText = v.Highlight[highlightKeyName][0]
|
|
|
+ } else {
|
|
|
+ item.SearchText = item.ExcelName
|
|
|
+ }
|
|
|
+ list = append(list, item)
|
|
|
+ searchMap[v.Id] = v.Id
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|