Browse Source

Es搜索添加专家背景

xingzai 3 years ago
parent
commit
ee975f1b1f
6 changed files with 22 additions and 163 deletions
  1. 1 0
      controllers/report.go
  2. 1 0
      controllers/tactics.go
  3. 1 1
      models/home.go
  4. 6 5
      models/search.go
  5. 2 0
      services/elastic.go
  6. 11 157
      services/task.go

+ 1 - 0
controllers/report.go

@@ -1029,6 +1029,7 @@ func (this *ReportController) ReportListNew() {
 			list[k].IsRed = true
 		}
 		list[k].IsResearch = true
+		list[k].ImgUrlPc = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211206/UvMadc63MLZY6rnQZQgGZAFXkqwf.png"
 		subjectNames, err := models.GetSubjectNames(v.ArticleId)
 		if err != nil {
 			br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)

+ 1 - 0
controllers/tactics.go

@@ -103,6 +103,7 @@ func (this *TacticsController) List() {
 		if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
 			list[k].IsRed = true
 		}
+		list[k].ImgUrlPc = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211206/UvMadc63MLZY6rnQZQgGZAFXkqwf.png"
 	}
 	if categoryId > 0 {
 		detail, errCategory := models.GetdetailByCategoryId(categoryId)

+ 1 - 1
models/home.go

@@ -19,7 +19,7 @@ func GetHomeCount(condition string, pars []interface{}) (count int, err error) {
 
 func GetHomeList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeArticle, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * ,(SELECT count(1) FROM cygx_article_history_record as h WHERE h.article_id = a.article_id ) as pv
+	sql := ` SELECT * ,(SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = a.article_id ) as pv
                  FROM cygx_article AS a
                 WHERE a.publish_status=1 `
 	if condition != "" {

+ 6 - 5
models/search.go

@@ -6,10 +6,11 @@ import (
 )
 
 type SearchItem struct {
-	ArticleId   int      `description:"文章id"`
-	Body        []string `description:"搜索结果"`
-	Title       string   `description:"标题"`
-	PublishDate string   `description:"发布时间"`
+	ArticleId        int      `description:"文章id"`
+	Body             []string `description:"搜索结果"`
+	Title            string   `description:"标题"`
+	PublishDate      string   `description:"发布时间"`
+	ExpertBackground string   `description:"专家背景"`
 }
 
 type CategoryItem struct {
@@ -30,4 +31,4 @@ func GetCategoryByCompanyId(companyId int) (items []*CategoryItem, err error) {
 type SearchResp struct {
 	Paging *paging.PagingItem
 	List   []*SearchItem
-}
+}

+ 2 - 0
services/elastic.go

@@ -788,6 +788,7 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
 						}
 						searchItem.Title = title
 						searchItem.PublishDate = article.PublishDate
+						searchItem.ExpertBackground = article.ExpertBackground
 						for _, v_result := range result {
 							if v_result.ArticleId == searchItem.ArticleId {
 								isAppend = true
@@ -884,6 +885,7 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
 				}
 				searchItem.Title = title
 				searchItem.PublishDate = article.PublishDate
+				searchItem.ExpertBackground = article.ExpertBackground
 				result = append(result, searchItem)
 			}
 		}

+ 11 - 157
services/task.go

@@ -72,160 +72,8 @@ func Task() {
 //editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * *   ", EditUserOutboundMobile) //同步外呼号码与手机号
 //task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
 
-func ElasticOption() {
-	//SyncTacticsList()
-	//toolbox.StartTask()
-	//keyWord := "专家"
-	//pageSize := 20
-	//SearchByKeyWord(keyWord, pageSize)
-	//SaveData()
-	//GetIndustryMap()
-	//解析报告
-	//GetArticleExpert()
-	//SearchByKeyWordQuery("")
-	//AddMap()
-
-	//同步数据
-	//ImportData()
-	//AddMap()
-	//Search("光伏行业")
-
-	//修复报告内容
-	//GetArticleAll()
-	//indexName := "article_list"
-	//		mappingJson := `{
-	//"mappings": {
-	// "dynamic": true,
-	// "properties": {
-	//   "ArticleId": {
-	//     "type": "integer"
-	//   },
-	//   "Title": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "TitleEn": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "UpdateFrequency": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "CreateDate": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "PublishDate": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "Abstract": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "CategoryName": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "SubCategoryName": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "InterviewDate": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "ExpertBackground": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "ExpertNumber": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "Department": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "BodyText": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   },
-	//   "ArticleIdMd5": {
-	//     "type": "text",
-	//     "analyzer": "ik_smart"
-	//   }
-	// }
-	//}
-	//}`
-	//EsCreateIndex(indexName,mappingJson)
-
-	//插入数据
-	//allList, err := models.GetArticleAll()
-	//if err != nil {
-	//	fmt.Println("GetArticleAll Err:", err.Error())
-	//	return
-	//}
-	//
-	//indexName := "article_list"
-	//
-	//for _, v := range allList {
-	//	content := html.UnescapeString(v.Body)
-	//	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
-	//	if err != nil {
-	//		fmt.Println("create doc err:", err.Error())
-	//		return
-	//	}
-	//	bodyText := doc.Text()
-	//
-	//	item := new(ElasticArticleDetail)
-	//	item.ArticleId = v.ArticleId
-	//	item.Title = v.Title
-	//	item.TitleEn = v.TitleEn
-	//	item.UpdateFrequency = v.UpdateFrequency
-	//	item.CreateDate = v.CreateDate
-	//	item.PublishDate = v.PublishDate
-	//	item.Abstract = v.Abstract
-	//	item.CategoryName = v.CategoryName
-	//	item.SubCategoryName = v.SubCategoryName
-	//	item.InterviewDate = v.InterviewDate
-	//	item.ExpertBackground = v.ExpertBackground
-	//	item.ExpertNumber = v.ExpertNumber
-	//	item.Department = v.Department
-	//	item.ArticleIdMd5 = v.ArticleIdMd5
-	//	item.BodyText = bodyText
-	//	EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
-	//}
-
-	//fmt.Println("bm")
-	//bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
-	////
-	//if err != nil {
-	//	fmt.Println("false",err)
-	//}
-	////fmt.Println(bm)
-	//key:="put_key_one"
-	////bm.Put(key,1,1*time.Second)
-	//b:=bm.IsExist(key)
-	//fmt.Println(b)
-
-	//同步策略文章
-	//SyncTacticsList()
-
-	//indexName := "article_list"
-	//EsDeleteData(indexName,)
-}
-
-/*
-searchItem := new(models.SearchItem)
-searchItem.ArticleId, _ = strconv.Atoi(v.Id)
-searchItem.Body = v.Highlight["BodyText"]
-searchItem.Title = title
-searchItem.PublishDate = article.PublishDate
-*/
 func CreateIndex() {
-	indexName := "cygx_article_v4" //utils.IndexName
+	indexName := "cygx_article_v1" //utils.IndexName
 	mappingJson := `{
  "mappings": {
    "dynamic": true,
@@ -258,6 +106,10 @@ func CreateIndex() {
      "UpdateFrequency": {
        "type": "text",
        "term_vector": "with_positions_offsets"
+     },
+     "ExpertBackground": {
+       "type": "text",
+       "term_vector": "with_positions_offsets"
      }
    }
  }
@@ -288,6 +140,7 @@ func AddAllArticle() {
 		item.Title = v.Title
 		item.PublishDate = v.PublishDate
 		item.BodyText = bodyText
+		item.ExpertBackground = v.ExpertBackground
 		EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
 		fmt.Println(v.ArticleId)
 	}
@@ -350,10 +203,11 @@ type ElasticArticleDetail struct {
 }
 
 type ElasticTestArticleDetail struct {
-	ArticleId   int    `description:"报告id"`
-	Title       string `description:"标题"`
-	BodyText    string `description:"内容"`
-	PublishDate string `description:"发布时间"`
+	ArticleId        int    `description:"报告id"`
+	Title            string `description:"标题"`
+	BodyText         string `description:"内容"`
+	PublishDate      string `description:"发布时间"`
+	ExpertBackground string `description:"专家背景"`
 }
 
 type ElasticTestArticleDetailV4 struct {