|
@@ -1504,108 +1504,3 @@ func SearchEdbInfoDataByAdminId(indexName, keywordStr string, from, size, filter
|
|
|
|
|
|
return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
|
|
|
}
|
|
|
-
|
|
|
-// SearchBaseFromYongyiIndex 查询es中的涌溢咨询指标
|
|
|
-func SearchBaseFromYongyiIndex(indexName, keywordStr string, from, size int) (total int64, list []*data_manage.EsBaseFromYongyiIndex, err error) {
|
|
|
- list = make([]*data_manage.EsBaseFromYongyiIndex, 0)
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("EsAddOrEditData Err:", err.Error())
|
|
|
- }
|
|
|
- }()
|
|
|
- client := utils.EsClient
|
|
|
-
|
|
|
- highlight := elastic.NewHighlight()
|
|
|
- highlight = highlight.Fields(elastic.NewHighlighterField("IndexName"))
|
|
|
- highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
|
|
|
-
|
|
|
- mustMap := make([]interface{}, 0)
|
|
|
-
|
|
|
- //关键字匹配
|
|
|
- shouldMap := map[string]interface{}{
|
|
|
- "should": []interface{}{
|
|
|
- map[string]interface{}{
|
|
|
- "match": map[string]interface{}{
|
|
|
- "IndexName": keywordStr,
|
|
|
- },
|
|
|
- },
|
|
|
- // 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
|
|
|
- map[string]interface{}{
|
|
|
- "match": map[string]interface{}{
|
|
|
- "IndexName": map[string]interface{}{
|
|
|
- "query": keywordStr,
|
|
|
- "operator": "and",
|
|
|
- },
|
|
|
- //"Frequency.keyword": "月度",
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- }
|
|
|
- mustMap = append(mustMap, map[string]interface{}{
|
|
|
- "bool": shouldMap,
|
|
|
- })
|
|
|
-
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "query": map[string]interface{}{
|
|
|
- "bool": map[string]interface{}{
|
|
|
- "must": mustMap,
|
|
|
- },
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
- //根据条件数量统计
|
|
|
- requestTotalHits := client.Count(indexName).BodyJson(queryMap)
|
|
|
- total, err = requestTotalHits.Do(context.Background())
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 分页查询
|
|
|
- queryMap["from"] = from
|
|
|
- queryMap["size"] = size
|
|
|
- jsonBytes, _ := json.Marshal(queryMap)
|
|
|
- fmt.Println(string(jsonBytes))
|
|
|
-
|
|
|
- request := client.Search(indexName).Highlight(highlight).Source(queryMap) // sets the JSON request
|
|
|
-
|
|
|
- //requestJson, err := json.Marshal(request)
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("requestJson err:", err)
|
|
|
- //}
|
|
|
- //fmt.Println("requestJson ", string(requestJson))
|
|
|
- searchMap := make(map[string]string)
|
|
|
-
|
|
|
- searchResp, err := request.Do(context.Background())
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println(searchResp)
|
|
|
- fmt.Println(searchResp.Status)
|
|
|
- if searchResp.Status != 0 {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if searchResp.Hits != nil {
|
|
|
- for _, v := range searchResp.Hits.Hits {
|
|
|
- if _, ok := searchMap[v.Id]; !ok {
|
|
|
- itemJson, tmpErr := v.Source.MarshalJSON()
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- fmt.Println("movieJson err:", err)
|
|
|
- return
|
|
|
- }
|
|
|
- item := new(data_manage.EsBaseFromYongyiIndex)
|
|
|
- tmpErr = json.Unmarshal(itemJson, &item)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("json.Unmarshal chartInfoJson err:", err)
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- list = append(list, item)
|
|
|
- searchMap[v.Id] = v.Id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
-}
|