task.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/toolbox"
  5. "hongze/hongze_cygx/utils"
  6. //"github.com/astaxie/beego/cache"
  7. )
  8. func Task() {
  9. fmt.Println("start")
  10. //同步数据
  11. if utils.RunMode == "release" {
  12. syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
  13. toolbox.AddTask("syncTacticsList", syncTacticsList)
  14. toolbox.StartTask()
  15. }
  16. //SyncCygxArticleList()
  17. fmt.Println("end")
  18. }
  19. func ElasticOption() {
  20. //SyncTacticsList()
  21. //toolbox.StartTask()
  22. //keyWord := "专家"
  23. //pageSize := 20
  24. //SearchByKeyWord(keyWord, pageSize)
  25. //SaveData()
  26. //GetIndustryMap()
  27. //解析报告
  28. //GetArticleExpert()
  29. //SearchByKeyWordQuery("")
  30. //AddMap()
  31. //同步数据
  32. //ImportData()
  33. //AddMap()
  34. //Search("光伏行业")
  35. //修复报告内容
  36. //GetArticleAll()
  37. //indexName := "article_list"
  38. // mappingJson := `{
  39. //"mappings": {
  40. // "dynamic": true,
  41. // "properties": {
  42. // "ArticleId": {
  43. // "type": "integer"
  44. // },
  45. // "Title": {
  46. // "type": "text",
  47. // "analyzer": "ik_smart"
  48. // },
  49. // "TitleEn": {
  50. // "type": "text",
  51. // "analyzer": "ik_smart"
  52. // },
  53. // "UpdateFrequency": {
  54. // "type": "text",
  55. // "analyzer": "ik_smart"
  56. // },
  57. // "CreateDate": {
  58. // "type": "text",
  59. // "analyzer": "ik_smart"
  60. // },
  61. // "PublishDate": {
  62. // "type": "text",
  63. // "analyzer": "ik_smart"
  64. // },
  65. // "Abstract": {
  66. // "type": "text",
  67. // "analyzer": "ik_smart"
  68. // },
  69. // "CategoryName": {
  70. // "type": "text",
  71. // "analyzer": "ik_smart"
  72. // },
  73. // "SubCategoryName": {
  74. // "type": "text",
  75. // "analyzer": "ik_smart"
  76. // },
  77. // "InterviewDate": {
  78. // "type": "text",
  79. // "analyzer": "ik_smart"
  80. // },
  81. // "ExpertBackground": {
  82. // "type": "text",
  83. // "analyzer": "ik_smart"
  84. // },
  85. // "ExpertNumber": {
  86. // "type": "text",
  87. // "analyzer": "ik_smart"
  88. // },
  89. // "Department": {
  90. // "type": "text",
  91. // "analyzer": "ik_smart"
  92. // },
  93. // "BodyText": {
  94. // "type": "text",
  95. // "analyzer": "ik_smart"
  96. // },
  97. // "ArticleIdMd5": {
  98. // "type": "text",
  99. // "analyzer": "ik_smart"
  100. // }
  101. // }
  102. //}
  103. //}`
  104. //EsCreateIndex(indexName,mappingJson)
  105. //插入数据
  106. //allList, err := models.GetArticleAll()
  107. //if err != nil {
  108. // fmt.Println("GetArticleAll Err:", err.Error())
  109. // return
  110. //}
  111. //
  112. //indexName := "article_list"
  113. //
  114. //for _, v := range allList {
  115. // content := html.UnescapeString(v.Body)
  116. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  117. // if err != nil {
  118. // fmt.Println("create doc err:", err.Error())
  119. // return
  120. // }
  121. // bodyText := doc.Text()
  122. //
  123. // item := new(ElasticArticleDetail)
  124. // item.ArticleId = v.ArticleId
  125. // item.Title = v.Title
  126. // item.TitleEn = v.TitleEn
  127. // item.UpdateFrequency = v.UpdateFrequency
  128. // item.CreateDate = v.CreateDate
  129. // item.PublishDate = v.PublishDate
  130. // item.Abstract = v.Abstract
  131. // item.CategoryName = v.CategoryName
  132. // item.SubCategoryName = v.SubCategoryName
  133. // item.InterviewDate = v.InterviewDate
  134. // item.ExpertBackground = v.ExpertBackground
  135. // item.ExpertNumber = v.ExpertNumber
  136. // item.Department = v.Department
  137. // item.ArticleIdMd5 = v.ArticleIdMd5
  138. // item.BodyText = bodyText
  139. // EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  140. //}
  141. //fmt.Println("bm")
  142. //bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
  143. ////
  144. //if err != nil {
  145. // fmt.Println("false",err)
  146. //}
  147. ////fmt.Println(bm)
  148. //key:="put_key_one"
  149. ////bm.Put(key,1,1*time.Second)
  150. //b:=bm.IsExist(key)
  151. //fmt.Println(b)
  152. //同步策略文章
  153. //SyncTacticsList()
  154. //indexName := "article_list"
  155. //EsDeleteData(indexName,)
  156. }
  157. /*
  158. searchItem := new(models.SearchItem)
  159. searchItem.ArticleId, _ = strconv.Atoi(v.Id)
  160. searchItem.Body = v.Highlight["BodyText"]
  161. searchItem.Title = title
  162. searchItem.PublishDate = article.PublishDate
  163. */
  164. func CreateIndex() {
  165. indexName := "cygx_article_test" //utils.IndexName
  166. mappingJson := `{
  167. "mappings": {
  168. "dynamic": true,
  169. "properties": {
  170. "ArticleId": {
  171. "type": "integer"
  172. },
  173. "BodyText": {
  174. "type": "text",
  175. "term_vector": "with_positions_offsets"
  176. },
  177. "PublishDate": {
  178. "type": "text"
  179. },
  180. "SubCategoryName": {
  181. "type": "text",
  182. "term_vector": "with_positions_offsets"
  183. },
  184. "Title": {
  185. "type": "text",
  186. "term_vector": "with_positions_offsets"
  187. },
  188. "TitleEn": {
  189. "type": "text",
  190. "term_vector": "with_positions_offsets"
  191. },
  192. "UpdateFrequency": {
  193. "type": "text",
  194. "term_vector": "with_positions_offsets"
  195. }
  196. }
  197. }
  198. }`
  199. EsCreateIndex(indexName, mappingJson)
  200. }
  201. // "term_vector": "with_positions_offsets"
  202. type ElasticArticleDetail struct {
  203. ArticleId int `description:"报告id"`
  204. Title string `description:"标题"`
  205. TitleEn string `description:"英文标题 "`
  206. UpdateFrequency string `description:"更新周期"`
  207. CreateDate string `description:"创建时间"`
  208. PublishDate string `description:"发布时间"`
  209. Abstract string `description:"摘要"`
  210. CategoryName string `description:"一级分类"`
  211. SubCategoryName string `description:"二级分类"`
  212. InterviewDate string `description:"访谈时间"`
  213. ExpertBackground string `description:"专家背景"`
  214. ExpertNumber string `description:"专家编号"`
  215. Department string `description:"作者"`
  216. ArticleIdMd5 string `description:"纪要id"`
  217. BodyText string `description:"内容"`
  218. }
  219. type ElasticTestArticleDetail struct {
  220. ArticleId int `description:"报告id"`
  221. Title string `description:"标题"`
  222. BodyText string `description:"内容"`
  223. PublishDate string `description:"发布时间"`
  224. }