task.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package services
  2. import (
  3. "fmt"
  4. //"github.com/astaxie/beego/cache"
  5. )
  6. func Task() {
  7. fmt.Println("start")
  8. //keyWord := "专家"
  9. //pageSize := 20
  10. //SearchByKeyWord(keyWord, pageSize)
  11. //SaveData()
  12. //GetIndustryMap()
  13. //解析报告
  14. //GetArticleExpert()
  15. //SearchByKeyWordQuery("")
  16. //AddMap()
  17. //同步数据
  18. //ImportData()
  19. //AddMap()
  20. //Search("光伏行业")
  21. //修复报告内容
  22. //GetArticleAll()
  23. //indexName := "article_list"
  24. // mappingJson := `{
  25. //"mappings": {
  26. // "dynamic": true,
  27. // "properties": {
  28. // "ArticleId": {
  29. // "type": "integer"
  30. // },
  31. // "Title": {
  32. // "type": "text",
  33. // "analyzer": "ik_smart"
  34. // },
  35. // "TitleEn": {
  36. // "type": "text",
  37. // "analyzer": "ik_smart"
  38. // },
  39. // "UpdateFrequency": {
  40. // "type": "text",
  41. // "analyzer": "ik_smart"
  42. // },
  43. // "CreateDate": {
  44. // "type": "text",
  45. // "analyzer": "ik_smart"
  46. // },
  47. // "PublishDate": {
  48. // "type": "text",
  49. // "analyzer": "ik_smart"
  50. // },
  51. // "Abstract": {
  52. // "type": "text",
  53. // "analyzer": "ik_smart"
  54. // },
  55. // "CategoryName": {
  56. // "type": "text",
  57. // "analyzer": "ik_smart"
  58. // },
  59. // "SubCategoryName": {
  60. // "type": "text",
  61. // "analyzer": "ik_smart"
  62. // },
  63. // "InterviewDate": {
  64. // "type": "text",
  65. // "analyzer": "ik_smart"
  66. // },
  67. // "ExpertBackground": {
  68. // "type": "text",
  69. // "analyzer": "ik_smart"
  70. // },
  71. // "ExpertNumber": {
  72. // "type": "text",
  73. // "analyzer": "ik_smart"
  74. // },
  75. // "Department": {
  76. // "type": "text",
  77. // "analyzer": "ik_smart"
  78. // },
  79. // "BodyText": {
  80. // "type": "text",
  81. // "analyzer": "ik_smart"
  82. // },
  83. // "ArticleIdMd5": {
  84. // "type": "text",
  85. // "analyzer": "ik_smart"
  86. // }
  87. // }
  88. //}
  89. //}`
  90. // EsCreateIndex(indexName,mappingJson)
  91. //插入数据
  92. //allList, err := models.GetArticleAll()
  93. //if err != nil {
  94. // fmt.Println("GetArticleAll Err:", err.Error())
  95. // return
  96. //}
  97. //
  98. ////indexName := "article"
  99. //
  100. //for _, v := range allList {
  101. // content := html.UnescapeString(v.Body)
  102. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  103. // if err != nil {
  104. // fmt.Println("create doc err:", err.Error())
  105. // return
  106. // }
  107. // bodyText := doc.Text()
  108. //
  109. // item := new(ElasticArticleDetail)
  110. // item.ArticleId = v.ArticleId
  111. // item.Title = v.Title
  112. // item.TitleEn = v.TitleEn
  113. // item.UpdateFrequency = v.UpdateFrequency
  114. // item.CreateDate = v.CreateDate
  115. // item.PublishDate = v.PublishDate
  116. // item.Abstract = v.Abstract
  117. // item.CategoryName = v.CategoryName
  118. // item.SubCategoryName = v.SubCategoryName
  119. // item.InterviewDate = v.InterviewDate
  120. // item.ExpertBackground = v.ExpertBackground
  121. // item.ExpertNumber = v.ExpertNumber
  122. // item.Department = v.Department
  123. // item.ArticleIdMd5 = v.ArticleIdMd5
  124. // item.BodyText = bodyText
  125. // EsAddData(indexName, strconv.Itoa(v.ArticleId), item)
  126. //}
  127. //fmt.Println("bm")
  128. //bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
  129. ////
  130. //if err != nil {
  131. // fmt.Println("false",err)
  132. //}
  133. ////fmt.Println(bm)
  134. //key:="put_key_one"
  135. ////bm.Put(key,1,1*time.Second)
  136. //b:=bm.IsExist(key)
  137. //fmt.Println(b)
  138. indexName := "article_list"
  139. keyWord:=`康立明`
  140. EsV7Search(indexName,keyWord)
  141. fmt.Println("end")
  142. }
  143. type ElasticArticleDetail struct {
  144. ArticleId int `description:"报告id"`
  145. Title string `description:"标题"`
  146. TitleEn string `description:"英文标题 "`
  147. UpdateFrequency string `description:"更新周期"`
  148. CreateDate string `description:"创建时间"`
  149. PublishDate string `description:"发布时间"`
  150. Abstract string `description:"摘要"`
  151. CategoryName string `description:"一级分类"`
  152. SubCategoryName string `description:"二级分类"`
  153. InterviewDate string `description:"访谈时间"`
  154. ExpertBackground string `description:"专家背景"`
  155. ExpertNumber string `description:"专家编号"`
  156. Department string `description:"作者"`
  157. ArticleIdMd5 string `description:"纪要id"`
  158. BodyText string `description:"内容"`
  159. }