ソースを参照

Merge branch 'feature/pool416_data_business_search' into debug

xyxie 3 日 前
コミット
93526bb822
1 ファイル変更33 行追加17 行削除
  1. 33 17
      services/elastic/elastic.go

+ 33 - 17
services/elastic/elastic.go

@@ -1978,44 +1978,60 @@ func SearchDataSourceIndex(indexName, keyword string, source, subSource int, cla
 	shouldMap := make(map[string]interface{}, 0)
 	if keyword != "" {
 		shouldMap["should"] = []interface{}{
+			// 精确匹配,最高优先级
 			map[string]interface{}{
-				"match": map[string]interface{}{
-					"IndexCode": map[string]interface{}{
-						"query":  keyword,
+				"term": map[string]interface{}{
+					"IndexCode.keyword": map[string]interface{}{
+						"value": keyword,
+						"boost": 10,
 					},
 				},
 			},
 			map[string]interface{}{
-				"match": map[string]interface{}{
-					"IndexName": map[string]interface{}{
-						"query":    keyword,
+				"term": map[string]interface{}{
+					"IndexName.keyword": map[string]interface{}{
+						"value": keyword,
+						"boost": 10,
 					},
 				},
 			},
+			// 短语匹配,次高优先级
 			map[string]interface{}{
 				"match_phrase": map[string]interface{}{
 					"IndexCode": map[string]interface{}{
-						"query":  keyword,
-						"boost":  5,
+						"query": keyword,
+						"boost": 5,
 					},
 				},
 			},
 			map[string]interface{}{
 				"match_phrase": map[string]interface{}{
 					"IndexName": map[string]interface{}{
-						"query":  keyword,
-						"boost":  5,
+						"query": keyword,
+						"boost": 5,
+					},
+				},
+			},
+			// 分词匹配,最低优先级
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"IndexCode": map[string]interface{}{
+						"query": keyword,
+						"boost": 1,
+					},
+				},
+			},
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"IndexName": map[string]interface{}{
+						"query": keyword,
+						"boost": 1,
 					},
 				},
 			},
 		}
-		//queryFields := []string{"IndexName.keyword", "IndexName.ik", "IndexName.ngram", "IndexCode.keyword", "IndexCode.ngram"}
-		//mustMap = append(mustMap, map[string]interface{}{
-		//	"multi_match": map[string]interface{}{
-		//		"query":  keyword,
-		//		"fields": queryFields,
-		//	},
-		//})
+		// 设置最小匹配度要求
+		shouldMap["minimum_should_match"] = 1
 	}
 
 	// 来源/子来源