xingzai 1 سال پیش
والد
کامیت
6fab796e33
3فایلهای تغییر یافته به همراه34 افزوده شده و 23 حذف شده
  1. 3 0
      controllers/search.go
  2. 19 9
      services/es_comprehensive.go
  3. 12 14
      utils/elastic.go

+ 3 - 0
controllers/search.go

@@ -741,6 +741,9 @@ func (this *SearchController) ComprehensiveList() {
 		br.ErrMsg = "检索失败,Err:" + err.Error()
 		return
 	}
+	//for _, v := range tmpResult {
+	//	fmt.Println(v.Title, "Title", v.IsSummary)
+	//}
 	list, err := services.GetResourceDataEsList(tmpResult, user)
 	if err != nil {
 		br.Msg = "获取失败"

+ 19 - 9
services/es_comprehensive.go

@@ -46,7 +46,7 @@ type ElasticComprehensiveDetail struct {
 }
 
 func init() {
-	AddComprehensiveArticle()
+	//AddComprehensiveArticle()
 	//AddComprehensiveActivity()
 	//AddComprehensiveIndustrialSource()
 	// AddComprehensiveMeetingreviewchapt()
@@ -739,10 +739,15 @@ func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*S
 	mustMap = append(mustMap, map[string]interface{}{
 		"bool": shouldMap,
 	})
+
 	mustNotMap = append(mustNotMap, map[string]interface{}{
-		"bool": shouldNotMap,
+		"term": shouldNotMap,
 	})
-
+	//mustMap = append(mustMap, map[string]interface{}{
+	//	"term": map[string]interface{}{
+	//		"IsSummary": "1",
+	//	},
+	//})
 	queryMap := map[string]interface{}{
 		"query": map[string]interface{}{
 			"bool": map[string]interface{}{
@@ -755,9 +760,9 @@ func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*S
 	queryMap["from"] = startSize
 	queryMap["size"] = pageSize
 	queryMap["highlight"] = highlightMap
-	jsonBytes, _ := json.Marshal(queryMap)
-	fmt.Println(string(jsonBytes))
-	utils.FileLog.Info(string(jsonBytes))
+	//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 {
@@ -773,7 +778,7 @@ func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*S
 				if err != nil {
 					return nil, 0, err
 				}
-				fmt.Println(article.SourceId, article.Title, article.Source)
+				//fmt.Println(article.SourceId, article.Title, article.Source)
 				searchItem := new(SearchComprehensiveItem)
 				searchItem.SourceId = article.SourceId
 				if len(v.Highlight["Annotation"]) > 0 {
@@ -791,7 +796,7 @@ func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*S
 						searchItem.Body = append(searchItem.Body, vText)
 					}
 				}
-
+				searchItem.IsSummary = article.IsSummary
 				if len(searchItem.Body) == 0 {
 					bodyRune := []rune(article.BodyText)
 					bodyRuneLen := len(bodyRune)
@@ -825,7 +830,7 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 	var condition string
 	var pars []interface{}
 	uid := user.UserId
-
+	titleHeight := make(map[int]string)
 	mapItems := make(map[string]*models.CygxResourceDataResp)
 	for _, v := range list {
 		//预处理文章
@@ -834,6 +839,8 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 		item.Source = v.Source
 		if v.IsSummary == 1 {
 			item.BodyHeight = v.Body
+			titleHeight[v.SourceId] = v.Title
+			//fmt.Println(v.Title)
 		} else {
 			item.BodyHeight = make([]string, 0)
 		}
@@ -902,6 +909,9 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 		for _, v := range listArticle {
 			v.Body = ""
 			v.BodyHtml = ""
+			if titleHeight[v.ArticleId] != "" {
+				v.Title = titleHeight[v.ArticleId]
+			}
 			mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
 		}
 	}

+ 12 - 14
utils/elastic.go

@@ -2,8 +2,6 @@ package utils
 
 import (
 	"github.com/olivere/elastic/v7"
-	"log"
-	"os"
 	"time"
 )
 
@@ -16,21 +14,21 @@ const (
 )
 
 func init() {
-	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
-	file := ""
-	if RunMode == "release" {
-		//file = `/data/rdlucklog/hongze_cygx/eslog.log`
-		file = `./rdlucklog/eslog.log`
-	} else {
-		file = `./rdlucklog/eslog.log`
-	}
-	logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
+	//errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
+	//file := ""
+	//if RunMode == "release" {
+	//	//file = `/data/rdlucklog/hongze_cygx/eslog.log`
+	//	file = `./rdlucklog/eslog.log`
+	//} else {
+	//	file = `./rdlucklog/eslog.log`
+	//}
+	//logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
 	client, err := elastic.NewClient(
 		elastic.SetURL(ES_URL),
 		elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
-		elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
-		elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
-	//elastic.SetSniff(false))
+		//elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
+		//elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
+		elastic.SetSniff(false))
 	Client = client
 	if err != nil {
 		go SendAlarmMsg("ElasticSearch连接失败", 2)