task.go 5.9 KB

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