Browse Source

改成按照摘要+内容搜索

xyxie 1 year ago
parent
commit
6cba3f29f2

+ 3 - 2
controller/english_report/english_report.go

@@ -265,8 +265,8 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 				resp.FailMsg("报告搜索失败 解析出错", "报告搜索失败,Err:"+tmpErr.Error(), c)
 				return
 			}
-			if len(v.Highlight["Title"]) > 0 {
-				reportItem.Title = v.Highlight["Title"][0]
+			if len(v.Highlight["Abstract"]) > 0 {
+				reportItem.Abstract = v.Highlight["Abstract"][0]
 			}
 			if reportItem.ReportId > 0 {
 				if len(v.Highlight["BodyContent"]) > 0 {
@@ -316,6 +316,7 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 		for _, reportItem := range tempList {
 			temp := new(english_report.SearchEnglishReportItem)
 			temp.Title = reportItem.Title
+			temp.Abstract = reportItem.Abstract
 			temp.Author = reportItem.Author
 			temp.CreateTime = reportItem.CreateTime
 			temp.ContentSub = reportItem.ContentSub

+ 1 - 0
models/english_report/report.go

@@ -124,6 +124,7 @@ type SearchEnglishReportItem struct {
 	ClassifyIdSecond   int    `json:"classify_id_second"`   //二级分类id
 	ClassifyNameSecond string `json:"classify_name_second"` //二级分类名称
 	Title              string `json:"title"`                //标题
+	Abstract           string `json:"abstract"`             //摘要
 	Author             string `json:"author"`               //作者
 	PublishTime        string `json:"publish_time"`         //发布时间
 	ReportCode         string `json:"report_code"`          //报告唯一编码

+ 14 - 14
services/elastic/report.go

@@ -15,11 +15,11 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 	if err != nil {
 		return
 	}
-	var must  []map[string]interface{}
+	var must []map[string]interface{}
 	shouldSub := []map[string]interface{}{
 		map[string]interface{}{
 			"match": map[string]interface{}{
-				"Title": map[string]interface{}{
+				"Abstract": map[string]interface{}{
 					"query": keyWord,
 					//"minimum_should_match": "60%",
 					"boost": 3,
@@ -37,7 +37,7 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 		},
 		map[string]interface{}{
 			"match_phrase": map[string]interface{}{
-				"Title": map[string]interface{}{
+				"Abstract": map[string]interface{}{
 					"query": keyWord,
 					//"slop": "50",
 					"boost": 5,
@@ -62,7 +62,7 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 	filterMust := []map[string]interface{}{
 		map[string]interface{}{
 			"term": map[string]interface{}{
-				"PublishState": 2,                     //必须是已发布的报告
+				"PublishState": 2, //必须是已发布的报告
 			},
 		},
 	}
@@ -74,7 +74,7 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 	source := map[string]interface{}{
 		"query": map[string]interface{}{
 			"bool": map[string]interface{}{
-				"must": must,
+				"must":   must,
 				"filter": filterMap,
 			},
 		},
@@ -83,30 +83,30 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 	source["size"] = size
 	source["highlight"] = map[string]interface{}{
 		"fields": map[string]interface{}{
-			"Title":map[string]interface{}{},
-			"BodyContent":map[string]interface{}{
+			"Abstract":    map[string]interface{}{},
+			"BodyContent": map[string]interface{}{
 				//	"pre_tags" : "{{highlight}}",
 				//	"post_tags": "{{/highlight}}",
 			},
 		},
-		"pre_tags" : "<span style=\"color:#00459F\">",
+		"pre_tags":  "<span style=\"color:#00459F\">",
 		"post_tags": "</span>",
 	}
 
 	source["sort"] = []map[string]interface{}{
 		map[string]interface{}{
-			"PublishTime.keyword":map[string]interface{}{
-				"order":"desc",
+			"PublishTime.keyword": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 		map[string]interface{}{
-			"_score":map[string]interface{}{
-				"order":"desc",
+			"_score": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 	}
 	jsonstr, err := json.Marshal(source)
-	fmt.Printf("%s",jsonstr)
+	fmt.Printf("%s", jsonstr)
 	request := client.Search(indexName).Source(source) // sets the JSON request
 
 	//requestJson, err := json.Marshal(request)
@@ -129,4 +129,4 @@ func SearchESEnglishReport(keyWord string, from, size int64) (searchResp *elasti
 	}
 	total = searchResp.TotalHits()
 	return
-}
+}