Browse Source

no message

xingzai 2 years ago
parent
commit
1fc3cf143e
1 changed files with 26 additions and 2 deletions
  1. 26 2
      services/elastic.go

+ 26 - 2
services/elastic.go

@@ -274,6 +274,28 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 					},
 				},
 			})
+			shouldMapquery = append(shouldMapquery, map[string]interface{}{
+				"function_score": map[string]interface{}{
+					"query": map[string]interface{}{
+						"multi_match": map[string]interface{}{
+							"boost":  (lenkeyWordArr - k) * boost, //给查询的值赋予权重
+							"fields": []interface{}{"Abstract"},
+							"query":  v,
+						},
+					},
+				},
+			})
+			shouldMapquery = append(shouldMapquery, map[string]interface{}{
+				"function_score": map[string]interface{}{
+					"query": map[string]interface{}{
+						"multi_match": map[string]interface{}{
+							"boost":  (lenkeyWordArr - k) * boost, //给查询的值赋予权重
+							"fields": []interface{}{"Annotation"},
+							"query":  v,
+						},
+					},
+				},
+			})
 
 			shouldMapquery = append(shouldMapquery, map[string]interface{}{
 				"function_score": map[string]interface{}{
@@ -303,8 +325,10 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 	highlightMap := make(map[string]interface{}, 0)
 	highlightMap = map[string]interface{}{
 		"fields": map[string]interface{}{
-			"BodyText": map[string]interface{}{},
-			"Title":    map[string]interface{}{},
+			"BodyText":   map[string]interface{}{},
+			"Title":      map[string]interface{}{},
+			"Abstract":   map[string]interface{}{},
+			"Annotation": map[string]interface{}{},
 		},
 		//样式 红色
 		"post_tags": []interface{}{"</font>"},