Browse Source

权重分配方式修改

xingzai 2 years ago
parent
commit
09a0f2d50c
1 changed files with 2 additions and 3 deletions
  1. 2 3
      services/elastic.go

+ 2 - 3
services/elastic.go

@@ -7,7 +7,6 @@ import (
 	"github.com/olivere/elastic/v7"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
-	"math"
 	"sort"
 	"strconv"
 	"strings"
@@ -915,7 +914,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":  math.Pow(10, float64(lenkeyWordArr-k)), //给查询的值赋予权重 10的n次方
+							"boost":  (lenkeyWordArr - k) * 100, //给查询的值赋予权重
 							"fields": []interface{}{"Title"},
 							"query":  v,
 						},
@@ -927,7 +926,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":  math.Pow(10, float64(lenkeyWordArr-k)) - 1, //给查询的值赋予权重 10的n次方
+							"boost":  (lenkeyWordArr-k)*100 - 1, //给查询的值赋予权重
 							"fields": []interface{}{"BodyText"},
 							"query":  v,
 						},