Kaynağa Gözat

产业报告搜索

xingzai 3 yıl önce
ebeveyn
işleme
6fc008755c
6 değiştirilmiş dosya ile 230 ekleme ve 17 silme
  1. 15 6
      controllers/activity.go
  2. 78 0
      controllers/search.go
  3. 28 0
      models/article.go
  4. 98 2
      services/elastic.go
  5. 10 8
      services/task.go
  6. 1 1
      utils/config.go

+ 15 - 6
controllers/activity.go

@@ -512,12 +512,21 @@ func (this *ActivityCoAntroller) GetUserSearchContent() {
 		return
 	}
 	uid := user.UserId
-	detail, err := models.GetUserSearchContentByUid(uid)
-	if err != nil {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取信息失败,Err:" + err.Error()
-		return
-	}
+
+	detailSeearch := new(models.CygxActivityUserSearchContent)
+	detailSeearch.IsShowJurisdiction = 0
+	detailSeearch.ChartPermissionids = ""
+	detailSeearch.ActiveState = ""
+
+	detail, _ := models.GetUserSearchContentByUid(uid)
+	if detail == nil {
+		detail = detailSeearch
+	}
+	//if err != nil {
+	//	br.Msg = "获取信息失败"
+	//	br.ErrMsg = "获取信息失败,Err:" + err.Error()
+	//	return
+	//}
 	isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
 	chartPermissionidsSlice := strings.Split(detail.ChartPermissionids, ",")
 	activityTypeidsSlice := strings.Split(detail.ActivityTypeids, ",")

+ 78 - 0
controllers/search.go

@@ -127,3 +127,81 @@ func (this *SearchController) SearchList() {
 
 //https://blog.csdn.net/my_miuye/article/details/110496025
 //search
+
+// @Title 报告搜索接口
+// @Description 报告搜索接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} models.SearchItem
+// @router /report/list [get]
+func (this *SearchController) SearchReport() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	keyWord := this.GetString("KeyWord")
+	if keyWord == "" {
+		br.Msg = "请输入搜索词"
+		br.ErrMsg = "请输入搜索词"
+		return
+	}
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	//indexName := "article_list"
+	indexName := utils.IndexName
+	pageSize = 100
+	var result []*models.SearchItem
+	var total int64
+	var err error
+	tmpResult, tmpTotal, tmpErr := services.EsSearchReport(indexName, keyWord, startSize, pageSize, user.UserId)
+	result = tmpResult
+	total = tmpTotal
+	err = tmpErr
+	if err != nil {
+		br.Msg = "检索失败"
+		br.ErrMsg = "检索失败,Err:" + err.Error()
+		return
+	}
+	if len(result) == 0 {
+		result = make([]*models.SearchItem, 0)
+	}
+	detail, errKey := models.GetNewSearchKeyWordByThisUser(user.UserId, keyWord)
+	if errKey != nil && errKey.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + errKey.Error()
+		return
+	}
+	//同一个用户一分钟之内搜索的词不重复记录
+	if detail == nil || time.Now().After(detail.CreateTime.Add(+time.Minute*1)) {
+		//fmt.Println("一分钟之内没有搜索")
+		keyWordItem := new(models.CygxSearchKeyWord)
+		keyWordItem.UserId = user.UserId
+		keyWordItem.KeyWord = keyWord
+		keyWordItem.CreateTime = time.Now()
+		go models.AddSearchKeyWord(keyWordItem)
+	}
+	resp := new(models.SearchResp)
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+	resp.Paging = page
+	resp.List = result
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 28 - 0
models/article.go

@@ -32,6 +32,34 @@ type CygxArticle struct {
 	MatchTypeName    string `description:"匹配类型"`
 }
 
+type CygxArticleEs struct {
+	Id               int    `orm:"column(id);pk"`
+	ArticleId        int    `description:"文章id"`
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	BodyText         string `description:"内容"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	PublishStatus    int    `description:"发布状态"`
+	CategoryId       int    `description:"分类id"`
+	ExpertBackground string `description:"专家背景"`
+	ExpertNumber     string `description:"专家编号"`
+	InterviewDate    string `description:"访谈日期"`
+	Department       string `description:"作者"`
+	ArticleIdMd5     string `description:"ID,md5值"`
+	IsClass          int    `description:"是否归类,1是,0否"`
+	IsSummary        bool   `description:"是否是纪要库,1是,0否"`
+	IsReport         bool   `description:"是否属于报告,1是,0否"`
+	ReportType       int    `description:"报告类型,1行业报告,2产业报告,0无"`
+	FileLink         string `description:"下载预览链接"`
+	MatchTypeName    string `description:"匹配类型"`
+}
+
 //新增文章
 func AddCygxArticle(item *CygxArticle) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 98 - 2
services/elastic.go

@@ -718,6 +718,7 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
 			boolquery := elastic.NewBoolQuery()
 			bodyFunctionQuery := elastic.NewFunctionScoreQuery()
 			bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
+			bodyFunctionQuery3 := elastic.NewFunctionScoreQuery()
 
 			//multiMatch := elastic.NewMultiMatchQuery(v, "Title", "BodyText").Analyzer("ik_smart")
 			multiMatch := elastic.NewMultiMatchQuery(v, "Title").Analyzer("ik_smart").Boost(10)
@@ -727,7 +728,12 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
 			multiMatch = elastic.NewMultiMatchQuery(v, "BodyText").Analyzer("ik_smart")
 			bodyFunctionQuery2.Query(multiMatch)
 			matchArr = append(matchArr, bodyFunctionQuery2)
-			boolquery.Should(matchArr...)
+
+			multiMatch = elastic.NewMultiMatchQuery(1, "IsSummary")
+			bodyFunctionQuery3.Query(multiMatch)
+			matchArr = append(matchArr, bodyFunctionQuery3)
+
+			boolquery.Must(matchArr...)
 
 			//multiMatch = elastic.NewMultiMatchQuery(v, "BodyText").Analyzer("ik_smart")
 			//bodyFunctionQuery.Query(multiMatch)
@@ -805,6 +811,7 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
 	keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
 	boolquery := elastic.NewBoolQuery()
 	matchArr := make([]elastic.Query, 0)
+	//matchArr2 := make([]elastic.Query, 0)
 
 	n := 0
 	keyWordLen := len(keyWordArr)
@@ -823,7 +830,14 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
 		}
 		n++
 	}
-	boolquery.Should(matchArr...)
+	//boolquery.Should(matchArr...)
+
+	//multiMatch2 := elastic.NewMultiMatchQuery(1, "IsSummary")
+	//bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
+	//bodyFunctionQuery2.Query(multiMatch2)
+	//matchArr2 = append(matchArr2, bodyFunctionQuery2)
+	//boolquery.Must(matchArr2...).Should(matchArr...)
+
 	highlight := elastic.NewHighlight()
 	highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
 	highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
@@ -874,3 +888,85 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
 	}
 	return
 }
+
+func EsSearchReport(indexName, keyWord string, startSize, pageSize, userId int) (result []*models.SearchItem, total int64, err error) {
+	client, err := NewClient()
+	keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
+	keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
+	n := 0
+	keyWordLen := len(keyWordArr)
+	if keyWordLen <= 0 {
+		keyWordArr = append(keyWordArr, keyWord)
+		keyWordLen = len(keyWordArr)
+	}
+	for _, v := range keyWordArr {
+		fmt.Println(v)
+	}
+
+	utils.FileLog.Info("SearchKeyWord:%s, userId:%s", keyWordArr, strconv.Itoa(userId))
+	for _, v := range keyWordArr {
+		if v != "" {
+			matchArr := make([]elastic.Query, 0)
+			boolquery := elastic.NewBoolQuery()
+			bodyFunctionQuery := elastic.NewFunctionScoreQuery()
+			bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
+
+			multiMatch := elastic.NewMultiMatchQuery(v, "Title").Analyzer("ik_smart")
+			bodyFunctionQuery.Query(multiMatch)
+			matchArr = append(matchArr, bodyFunctionQuery)
+
+			multiMatch = elastic.NewMultiMatchQuery(1, "IsReport")
+			bodyFunctionQuery2.Query(multiMatch)
+			matchArr = append(matchArr, bodyFunctionQuery2)
+			boolquery.Must(matchArr...)
+
+			highlight := elastic.NewHighlight()
+			highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
+			highlight = highlight.Fields(elastic.NewHighlighterField("Title"))
+			request := client.Search(indexName).Highlight(highlight).Sort("PublishDate", false).From(0).Size(pageSize).Query(boolquery)
+
+			searchByMatch, err := request.Do(context.Background())
+			if err != nil {
+				return nil, 0, err
+			}
+			if searchByMatch != nil {
+				if searchByMatch.Hits != nil {
+					for _, v := range searchByMatch.Hits.Hits {
+						var isAppend bool
+						articleJson, err := v.Source.MarshalJSON()
+						if err != nil {
+							return nil, 0, err
+						}
+						article := new(models.CygxArticle)
+						err = json.Unmarshal(articleJson, &article)
+						if err != nil {
+							return nil, 0, err
+						}
+						searchItem := new(models.SearchItem)
+						searchItem.ArticleId, _ = strconv.Atoi(v.Id)
+
+						var title string
+						if len(v.Highlight["Title"]) > 0 {
+							title = v.Highlight["Title"][0]
+						} else {
+							title = article.Title
+						}
+						searchItem.Title = title
+						searchItem.PublishDate = article.PublishDate
+						for _, v_result := range result {
+							if v_result.ArticleId == searchItem.ArticleId {
+								isAppend = true
+							}
+						}
+						if !isAppend {
+							result = append(result, searchItem)
+						}
+					}
+				}
+			}
+		}
+		n++
+	}
+	total = int64(len(result))
+	return
+}

+ 10 - 8
services/task.go

@@ -292,12 +292,14 @@ func AddAllArticleV4() {
 		item.Title = v.Title
 		item.PublishDate = v.PublishDate
 		item.BodyText = bodyText
-		if v.IsReport == 1 {
-			item.IsReport = true
-		}
-		if v.IsSummary == 1 {
-			item.IsSummary = true
-		}
+		item.IsSummary = v.IsSummary
+		item.IsReport = v.IsReport
+		//if v.IsReport == 1 {
+		//	item.IsReport = true
+		//}
+		//if v.IsSummary == 1 {
+		//	item.IsSummary = true
+		//}
 		EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
 		fmt.Println(v.ArticleId)
 	}
@@ -335,6 +337,6 @@ type ElasticTestArticleDetailV4 struct {
 	Title       string `description:"标题"`
 	BodyText    string `description:"内容"`
 	PublishDate string `description:"发布时间"`
-	IsSummary   bool   `description:"是否属于纪要库"`
-	IsReport    bool   `description:"是否属于报告"`
+	IsSummary   int    `description:"是否属于纪要库"`
+	IsReport    int    `description:"是否属于报告"`
 }

+ 1 - 1
utils/config.go

@@ -90,7 +90,7 @@ func init() {
 		WxPublicAppId = "wx9b5d7291e581233a"
 		WxPublicAppSecret = "f4d52e34021eee262dce9682b31f8861"
 		WxPublicId = "gh_5dc508325c6f"
-		IndexName = "cygx_article_v1"
+		IndexName = "cygx_article_v4"
 	}
 }