|
@@ -255,20 +255,21 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
shouldMapquery := make([]interface{}, 0)
|
|
|
// @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
|
|
|
//keyWordWeight := GetWeight(keyWordLen)
|
|
|
- //var boost int
|
|
|
+ var boost int
|
|
|
//lenkeyWordArr := len(keyWordArr)
|
|
|
- for _, v := range keyWordArr {
|
|
|
- //if k == 0 {
|
|
|
- // boost = 2 * 1000
|
|
|
- //} else {
|
|
|
- // boost = 1000
|
|
|
- //}
|
|
|
+ for k, v := range keyWordArr {
|
|
|
+ if k == 0 {
|
|
|
+ boost = 2 * 1000
|
|
|
+ } else {
|
|
|
+ boost = 1
|
|
|
+ }
|
|
|
if 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, //给查询的值赋予权重
|
|
|
+ "boost": boost, //给查询的值赋予权重
|
|
|
"fields": []interface{}{"Title"},
|
|
|
"query": v,
|
|
|
},
|
|
@@ -279,7 +280,7 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
"function_score": map[string]interface{}{
|
|
|
"query": map[string]interface{}{
|
|
|
"multi_match": map[string]interface{}{
|
|
|
- //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
|
|
|
+ "boost": boost, //给查询的值赋予权重
|
|
|
"fields": []interface{}{"Abstract"},
|
|
|
"query": v,
|
|
|
},
|
|
@@ -290,7 +291,7 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
"function_score": map[string]interface{}{
|
|
|
"query": map[string]interface{}{
|
|
|
"multi_match": map[string]interface{}{
|
|
|
- //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
|
|
|
+ "boost": boost, //给查询的值赋予权重
|
|
|
"fields": []interface{}{"Annotation"},
|
|
|
"query": v,
|
|
|
},
|
|
@@ -303,6 +304,7 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
"query": map[string]interface{}{
|
|
|
"multi_match": map[string]interface{}{
|
|
|
//"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
|
|
|
+ "boost": boost, //给查询的值赋予权重
|
|
|
"fields": []interface{}{"BodyText"},
|
|
|
"query": v,
|
|
|
},
|
|
@@ -316,6 +318,12 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
}
|
|
|
//排序
|
|
|
sortMap := make([]interface{}, 0)
|
|
|
+
|
|
|
+ sortMap = append(sortMap, map[string]interface{}{
|
|
|
+ "_score": map[string]interface{}{
|
|
|
+ "order": "desc",
|
|
|
+ },
|
|
|
+ })
|
|
|
//时间
|
|
|
sortMap = append(sortMap, map[string]interface{}{
|
|
|
"PublishDate": map[string]interface{}{
|
|
@@ -354,6 +362,7 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
|
|
|
queryMap["highlight"] = highlightMap
|
|
|
jsonBytes, _ := json.Marshal(queryMap)
|
|
|
fmt.Println(string(jsonBytes))
|
|
|
+ //utils.FileLog.Info(string(jsonBytes))
|
|
|
request := client.Search(indexName).Source(queryMap) // sets the JSON request
|
|
|
searchByMatch, err := request.Do(context.Background())
|
|
|
if searchByMatch != nil {
|