search.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "strings"
  8. )
  9. type SearchController struct {
  10. BaseAuthController
  11. }
  12. type BaseSearchController struct {
  13. BaseCommonController
  14. }
  15. // @Title 搜索接口
  16. // @Description 搜索接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string true "搜索关键词"
  20. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  21. // @Success 200 {object} models.SearchItem
  22. // @router /list [get]
  23. func (this *SearchController) SearchList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. pageSize, _ := this.GetInt("PageSize")
  30. currentIndex, _ := this.GetInt("CurrentIndex")
  31. var startSize int
  32. if pageSize <= 0 {
  33. pageSize = utils.PageSize20
  34. }
  35. if currentIndex <= 0 {
  36. currentIndex = 1
  37. }
  38. startSize = paging.StartIndex(currentIndex, pageSize)
  39. keyWord := this.GetString("KeyWord")
  40. orderColumn := this.GetString("OrderColumn")
  41. if keyWord == "" {
  42. br.Msg = "请输入搜索词"
  43. br.ErrMsg = "请输入搜索词"
  44. return
  45. }
  46. user := this.User
  47. if user == nil {
  48. br.Msg = "请重新登录"
  49. br.Ret = 408
  50. return
  51. }
  52. //研选的五张图片
  53. detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
  54. if errConfig != nil {
  55. br.Msg = "获取数据失败"
  56. br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
  57. return
  58. }
  59. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  60. //对应分类的所图片
  61. detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
  62. if errConfig != nil {
  63. br.Msg = "获取数据失败"
  64. br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
  65. return
  66. }
  67. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  68. mapCategoryUrl := make(map[string]string)
  69. var categoryId string
  70. var imgUrlChart string
  71. for _, v := range categoryUrlList {
  72. vslice := strings.Split(v, "_")
  73. categoryId = vslice[0]
  74. imgUrlChart = vslice[len(vslice)-1]
  75. mapCategoryUrl[categoryId] = imgUrlChart
  76. }
  77. if orderColumn == "" {
  78. orderColumn = "Matching"
  79. }
  80. indexName := utils.IndexName
  81. pageSize = 20
  82. var result []*models.SearchItem
  83. var total int64
  84. var err error
  85. if orderColumn == "PublishDate" {
  86. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
  87. result = tmpResult
  88. total = tmpTotal
  89. err = tmpErr
  90. } else {
  91. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
  92. result = tmpResult
  93. total = tmpTotal
  94. err = tmpErr
  95. }
  96. if err != nil {
  97. br.Msg = "检索失败"
  98. br.ErrMsg = "检索失败,Err:" + err.Error()
  99. return
  100. }
  101. if len(result) == 0 {
  102. result = make([]*models.SearchItem, 0)
  103. }
  104. //记录用户搜索关键词
  105. go services.AddSearchKeyWord(user, keyWord, 1)
  106. for k, v := range result {
  107. //如果是研选系列的任意取五张图片的中的一张
  108. if v.CategoryId == "0" {
  109. knum := v.ArticleId % 5
  110. result[k].ImgUrlPc = researchList[knum]
  111. } else {
  112. result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  113. }
  114. }
  115. resp := new(models.SearchResp)
  116. page := paging.GetPaging(currentIndex, pageSize, int(total))
  117. resp.Paging = page
  118. resp.List = result
  119. br.Ret = 200
  120. br.Success = true
  121. br.Msg = "获取成功"
  122. br.Data = resp
  123. }
  124. //https://blog.csdn.net/my_miuye/article/details/110496025
  125. //search
  126. // @Title 报告搜索接口
  127. // @Description 报告搜索接口
  128. // @Param PageSize query int true "每页数据条数"
  129. // @Param CurrentIndex query int true "当前页页码,从1开始"
  130. // @Param KeyWord query string true "搜索关键词"
  131. // @Success 200 {object} models.SearchItem
  132. // @router /report/list [get]
  133. func (this *SearchController) SearchReport() {
  134. br := new(models.BaseResponse).Init()
  135. defer func() {
  136. this.Data["json"] = br
  137. this.ServeJSON()
  138. }()
  139. pageSize, _ := this.GetInt("PageSize")
  140. currentIndex, _ := this.GetInt("CurrentIndex")
  141. var startSize int
  142. if pageSize <= 0 {
  143. pageSize = utils.PageSize20
  144. }
  145. if currentIndex <= 0 {
  146. currentIndex = 1
  147. }
  148. startSize = paging.StartIndex(currentIndex, pageSize)
  149. keyWord := this.GetString("KeyWord")
  150. if keyWord == "" {
  151. br.Msg = "请输入搜索词"
  152. br.ErrMsg = "请输入搜索词"
  153. return
  154. }
  155. user := this.User
  156. if user == nil {
  157. br.Msg = "请重新登录"
  158. br.Ret = 408
  159. return
  160. }
  161. //indexName := "article_list"
  162. indexName := utils.IndexName
  163. pageSize = 100
  164. var result []*models.SearchItem
  165. var total int64
  166. var err error
  167. tmpResult, tmpTotal, tmpErr := services.EsSearchReport(indexName, keyWord, startSize, pageSize, user.UserId)
  168. result = tmpResult
  169. total = tmpTotal
  170. err = tmpErr
  171. if err != nil {
  172. br.Msg = "检索失败"
  173. br.ErrMsg = "检索失败,Err:" + err.Error()
  174. return
  175. }
  176. if len(result) == 0 {
  177. result = make([]*models.SearchItem, 0)
  178. }
  179. //记录用户搜索关键词
  180. go services.AddSearchKeyWord(user, keyWord, 1)
  181. resp := new(models.SearchResp)
  182. page := paging.GetPaging(currentIndex, pageSize, int(total))
  183. resp.Paging = page
  184. resp.List = result
  185. br.Ret = 200
  186. br.Success = true
  187. br.Msg = "获取成功"
  188. br.Data = resp
  189. }
  190. // @Title 搜索接口(无需token)
  191. // @Description 搜索接口(无需token)
  192. // @Param PageSize query int true "每页数据条数"
  193. // @Param CurrentIndex query int true "当前页页码,从1开始"
  194. // @Param KeyWord query string true "搜索关键词"
  195. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  196. // @Param CompanyCode query string false "机构编号"
  197. // @Param CompanyName query string false "机构名称"
  198. // @Param Email query string false "邮箱"
  199. // @Param Sign query string false "加密签名"
  200. // @Success 200 {object} models.SearchItem
  201. // @router /listPublic [get]
  202. func (this *BaseSearchController) SearchListPublic() {
  203. br := new(models.BaseResponse).Init()
  204. defer func() {
  205. this.Data["json"] = br
  206. this.ServeJSON()
  207. }()
  208. pageSize, _ := this.GetInt("PageSize")
  209. currentIndex, _ := this.GetInt("CurrentIndex")
  210. var startSize int
  211. if pageSize <= 0 {
  212. pageSize = utils.PageSize20
  213. }
  214. if currentIndex <= 0 {
  215. currentIndex = 1
  216. }
  217. startSize = paging.StartIndex(currentIndex, pageSize)
  218. keyWord := this.GetString("KeyWord")
  219. orderColumn := this.GetString("OrderColumn")
  220. if keyWord == "" {
  221. br.Msg = "请输入搜索词"
  222. br.ErrMsg = "请输入搜索词"
  223. return
  224. }
  225. companyCode := this.GetString("CompanyCode")
  226. companyNameHt := this.GetString("CompanyName")
  227. email := this.GetString("Email")
  228. sign := this.GetString("Sign")
  229. if orderColumn == "" {
  230. orderColumn = "Matching"
  231. }
  232. indexName := utils.IndexName
  233. pageSize = 20
  234. var result []*models.SearchItem
  235. var total int64
  236. var err error
  237. if orderColumn == "PublishDate" {
  238. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, 0)
  239. result = tmpResult
  240. total = tmpTotal
  241. err = tmpErr
  242. } else {
  243. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, 0, orderColumn)
  244. result = tmpResult
  245. total = tmpTotal
  246. err = tmpErr
  247. }
  248. if err != nil {
  249. br.Msg = "检索失败"
  250. br.ErrMsg = "检索失败,Err:" + err.Error()
  251. return
  252. }
  253. if len(result) == 0 {
  254. result = make([]*models.SearchItem, 0)
  255. }
  256. if companyCode != "" && companyNameHt != "" && email != "" {
  257. errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  258. if errHt != nil {
  259. br.Msg = "获取"
  260. br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
  261. return
  262. }
  263. if errMsg != "" {
  264. br.Msg = errMsg
  265. return
  266. }
  267. user := wxUser
  268. userItem := new(models.WxUserItem)
  269. userItem.UserId = user.UserId
  270. userItem.Mobile = user.Mobile
  271. userItem.Email = user.Email
  272. userItem.CompanyId = user.CompanyId
  273. userItem.RealName = user.RealName
  274. //记录用户搜索关键词
  275. go services.AddSearchKeyWord(userItem, keyWord, 1)
  276. }
  277. for k, _ := range result {
  278. if result[k].ArticleId < utils.SummaryArticleId {
  279. result[k].IsNeedJump = true
  280. }
  281. }
  282. resp := new(models.SearchResp)
  283. page := paging.GetPaging(currentIndex, pageSize, int(total))
  284. resp.Paging = page
  285. resp.List = result
  286. br.Ret = 200
  287. br.Success = true
  288. br.Msg = "获取成功"
  289. br.Data = resp
  290. }
  291. // @Title 搜索接口
  292. // @Description 搜索接口
  293. // @Param PageSize query int true "每页数据条数"
  294. // @Param CurrentIndex query int true "当前页页码,从1开始"
  295. // @Param KeyWord query string true "搜索关键词"
  296. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  297. // @Param ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
  298. // @Success 200 {object} models.SearchItem
  299. // @router /artAndChart/list [get]
  300. func (this *SearchController) ListHomeArtAndChart() {
  301. br := new(models.BaseResponse).Init()
  302. defer func() {
  303. this.Data["json"] = br
  304. this.ServeJSON()
  305. }()
  306. pageSize, _ := this.GetInt("PageSize")
  307. currentIndex, _ := this.GetInt("CurrentIndex")
  308. listType, _ := this.GetInt("ListType")
  309. var startSize int
  310. if pageSize <= 0 {
  311. pageSize = utils.PageSize20
  312. }
  313. if currentIndex <= 0 {
  314. currentIndex = 1
  315. }
  316. startSize = paging.StartIndex(currentIndex, pageSize)
  317. keyWord := this.GetString("KeyWord")
  318. orderColumn := this.GetString("OrderColumn")
  319. if keyWord == "" {
  320. br.Msg = "请输入搜索词"
  321. br.ErrMsg = "请输入搜索词"
  322. return
  323. }
  324. user := this.User
  325. if user == nil {
  326. br.Msg = "请重新登录"
  327. br.Ret = 408
  328. return
  329. }
  330. //研选的五张图片
  331. detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
  332. if errConfig != nil {
  333. br.Msg = "获取数据失败"
  334. br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
  335. return
  336. }
  337. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  338. //对应分类的所图片
  339. detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
  340. if errConfig != nil {
  341. br.Msg = "获取数据失败"
  342. br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
  343. return
  344. }
  345. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  346. mapCategoryUrl := make(map[string]string)
  347. var categoryId string
  348. var imgUrlChart string
  349. for _, v := range categoryUrlList {
  350. vslice := strings.Split(v, "_")
  351. categoryId = vslice[0]
  352. imgUrlChart = vslice[len(vslice)-1]
  353. mapCategoryUrl[categoryId] = imgUrlChart
  354. }
  355. if orderColumn == "" {
  356. orderColumn = "Matching"
  357. }
  358. indexName := utils.IndexName
  359. pageSize = 20
  360. var chartTotal int
  361. resp := new(models.SearchResp)
  362. //page := paging.GetPaging(currentIndex, pageSize, total)
  363. var chartList []*models.HomeChartListResp
  364. var err error
  365. var condition string
  366. var pars []interface{}
  367. if listType == 1 || listType == 3 {
  368. if listType == 1 {
  369. pageSize = 100
  370. }
  371. if currentIndex <= 2 {
  372. condition = ` AND title LIKE '%` + keyWord + `%'`
  373. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  374. if err != nil {
  375. br.Msg = "获取信息失败"
  376. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  377. return
  378. }
  379. chartTotal, err = models.GetChartCount(condition, pars)
  380. if err != nil {
  381. br.Msg = "获取信息失败"
  382. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  383. return
  384. }
  385. }
  386. }
  387. for k, v := range chartList {
  388. chartList[k].IsNeedJump = true
  389. chartList[k].Source = 2
  390. if v.PtagName != "" {
  391. chartList[k].CtagNamePc = v.PtagName
  392. }
  393. if v.CtagName != "" {
  394. chartList[k].CtagNamePc += "," + v.CtagName
  395. }
  396. if v.PtagNameTwo != "" {
  397. chartList[k].CtagNamePc += "," + v.PtagNameTwo
  398. }
  399. if v.CtagNameTwo != "" {
  400. chartList[k].CtagNamePc += "," + v.CtagNameTwo
  401. }
  402. }
  403. if len(chartList) == 0 {
  404. chartList = make([]*models.HomeChartListResp, 0)
  405. }
  406. resp.ChartList = chartList
  407. var result []*models.SearchItem
  408. var total int64
  409. if listType == 1 || listType == 2 {
  410. if orderColumn == "PublishDate" {
  411. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
  412. result = tmpResult
  413. total = tmpTotal
  414. err = tmpErr
  415. } else {
  416. tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
  417. result = tmpResult
  418. total = tmpTotal
  419. err = tmpErr
  420. }
  421. if err != nil {
  422. br.Msg = "检索失败"
  423. br.ErrMsg = "检索失败,Err:" + err.Error()
  424. return
  425. }
  426. if len(result) == 0 {
  427. result = make([]*models.SearchItem, 0)
  428. }
  429. for k, v := range result {
  430. //如果是研选系列的任意取五张图片的中的一张
  431. if v.CategoryId == "0" {
  432. knum := v.ArticleId % 5
  433. result[k].ImgUrlPc = researchList[knum]
  434. } else {
  435. result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  436. }
  437. result[k].Source = 1
  438. result[k].PublishDate = utils.StrTimeToTime(result[k].PublishDate).Format(utils.FormatDate)
  439. }
  440. }
  441. // ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
  442. //记录用户搜索关键词
  443. var source int
  444. if listType == 1 {
  445. source = 3
  446. } else if listType == 2 {
  447. source = 1
  448. } else {
  449. source = 2
  450. }
  451. go services.AddSearchKeyWord(user, keyWord, source)
  452. if chartTotal > int(total) {
  453. total = int64(chartTotal)
  454. }
  455. if listType == 1 {
  456. total = total + int64(chartTotal)
  457. }
  458. if len(result) == 0 {
  459. result = make([]*models.SearchItem, 0)
  460. }
  461. page := paging.GetPaging(currentIndex, pageSize, int(total))
  462. resp.Paging = page
  463. resp.List = result
  464. br.Ret = 200
  465. br.Success = true
  466. br.Msg = "获取成功"
  467. br.Data = resp
  468. }
  469. // @Title 搜索接口
  470. // @Description 搜索接口
  471. // @Param PageSize query int true "每页数据条数"
  472. // @Param CurrentIndex query int true "当前页页码,从1开始"
  473. // @Param KeyWord query string true "搜索关键词"
  474. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  475. // @Success 200 {object} models.SearchItem
  476. // @router /artAndChart/listPage [get]
  477. func (this *SearchController) ListHomeArtAndChartPage() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. this.Data["json"] = br
  481. this.ServeJSON()
  482. }()
  483. pageSize, _ := this.GetInt("PageSize")
  484. currentIndex, _ := this.GetInt("CurrentIndex")
  485. // @Param ListType query int true "列表类型,1最新/全部,2 纪要 ,3图表 默认1"
  486. listType, _ := this.GetInt("ListType")
  487. var startSize int
  488. if pageSize <= 0 {
  489. pageSize = utils.PageSize20
  490. }
  491. if currentIndex <= 0 {
  492. currentIndex = 1
  493. }
  494. listType = 1
  495. startSize = paging.StartIndex(currentIndex, pageSize)
  496. keyWord := this.GetString("KeyWord")
  497. orderColumn := this.GetString("OrderColumn")
  498. if keyWord == "" {
  499. br.Msg = "请输入搜索词"
  500. br.ErrMsg = "请输入搜索词"
  501. return
  502. }
  503. user := this.User
  504. if user == nil {
  505. br.Msg = "请重新登录"
  506. br.Ret = 408
  507. return
  508. }
  509. //研选的五张图片
  510. detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
  511. if errConfig != nil {
  512. br.Msg = "获取数据失败"
  513. br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
  514. return
  515. }
  516. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  517. //对应分类的所图片
  518. detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
  519. if errConfig != nil {
  520. br.Msg = "获取数据失败"
  521. br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
  522. return
  523. }
  524. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  525. mapCategoryUrl := make(map[string]string)
  526. var categoryId string
  527. var imgUrlChart string
  528. for _, v := range categoryUrlList {
  529. vslice := strings.Split(v, "_")
  530. categoryId = vslice[0]
  531. imgUrlChart = vslice[len(vslice)-1]
  532. mapCategoryUrl[categoryId] = imgUrlChart
  533. }
  534. if orderColumn == "" {
  535. orderColumn = "Matching"
  536. }
  537. var chartTotal int
  538. resp := new(models.SearchResp)
  539. var chartList []*models.HomeChartListResp
  540. var err error
  541. var condition string
  542. var pars []interface{}
  543. if listType == 1 || listType == 3 {
  544. if currentIndex <= 2 {
  545. condition = ` AND title LIKE '%` + keyWord + `%'`
  546. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  547. if err != nil {
  548. br.Msg = "获取信息失败"
  549. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  550. return
  551. }
  552. chartTotal, err = models.GetChartCount(condition, pars)
  553. if err != nil {
  554. br.Msg = "获取信息失败"
  555. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  556. return
  557. }
  558. }
  559. }
  560. for k, v := range chartList {
  561. chartList[k].IsNeedJump = true
  562. chartList[k].Source = 2
  563. if v.PtagName != "" {
  564. chartList[k].CtagNamePc = v.PtagName
  565. }
  566. if v.CtagName != "" {
  567. chartList[k].CtagNamePc += "," + v.CtagName
  568. }
  569. if v.PtagNameTwo != "" {
  570. chartList[k].CtagNamePc += "," + v.PtagNameTwo
  571. }
  572. if v.CtagNameTwo != "" {
  573. chartList[k].CtagNamePc += "," + v.CtagNameTwo
  574. }
  575. }
  576. if len(chartList) == 0 {
  577. chartList = make([]*models.HomeChartListResp, 0)
  578. }
  579. resp.ChartList = chartList
  580. var result []*models.SearchItem
  581. var total int64
  582. var articleIds []int
  583. if listType == 1 || listType == 2 {
  584. //添加映射关系
  585. keyWord = strings.ToUpper(keyWord)
  586. keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
  587. if keyWordDetail != nil {
  588. keyWord = keyWordDetail.KeyWordMap
  589. }
  590. _, tmpTotal, err := services.EsArticleSearch(keyWord, startSize, pageSize, orderColumn, 0)
  591. if err != nil {
  592. br.Msg = "检索失败"
  593. br.ErrMsg = "检索失败,Err:" + err.Error()
  594. return
  595. }
  596. tmpResult, tmpTotalResult, err := services.EsArticleSearchBody(keyWord, startSize, pageSize, orderColumn, 1)
  597. if err != nil {
  598. br.Msg = "检索失败"
  599. br.ErrMsg = "检索失败,Err:" + err.Error()
  600. return
  601. }
  602. result = tmpResult
  603. if int(tmpTotalResult) < currentIndex*pageSize {
  604. startSizeBody := startSize - int(tmpTotalResult)
  605. if startSizeBody < 0 {
  606. startSizeBody = 0
  607. }
  608. var pageSizeBody int
  609. pageSizeBody = pageSize - len(tmpResult)
  610. tmpResultBody, tmpTotalBody, err := services.EsArticleSearchBody(keyWord, startSizeBody, pageSizeBody, orderColumn, 2)
  611. if err != nil {
  612. br.Msg = "检索失败"
  613. br.ErrMsg = "检索失败,Err:" + err.Error()
  614. return
  615. }
  616. for _, v := range tmpResultBody {
  617. result = append(result, v)
  618. }
  619. tmpTotalResult += tmpTotalBody
  620. }
  621. if int(tmpTotalResult) < currentIndex*pageSize {
  622. startSizeIk := startSize - int(tmpTotalResult)
  623. if startSizeIk < 0 {
  624. startSizeIk = 0
  625. }
  626. var pageSizeIk int
  627. pageSizeIk = pageSize - len(result)
  628. tmpResultIk, _, err := services.EsArticleSearch(keyWord, startSizeIk, pageSizeIk, orderColumn, 2)
  629. if err != nil {
  630. br.Msg = "检索失败"
  631. br.ErrMsg = "检索失败,Err:" + err.Error()
  632. return
  633. }
  634. for _, v := range tmpResultIk {
  635. result = append(result, v)
  636. }
  637. }
  638. total = tmpTotal
  639. if len(result) == 0 {
  640. result = make([]*models.SearchItem, 0)
  641. }
  642. for k, v := range result {
  643. //如果是研选系列的任意取五张图片的中的一张
  644. if v.CategoryId == "0" {
  645. knum := v.ArticleId % 5
  646. result[k].ImgUrlPc = researchList[knum]
  647. } else {
  648. result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  649. }
  650. result[k].Source = 1
  651. v.PublishDate = utils.TimeRemoveHms(v.PublishDate)
  652. articleIds = append(articleIds, v.ArticleId)
  653. }
  654. }
  655. //记录用户搜索关键词
  656. //var source int
  657. //if listType == 1 {
  658. // source = 3
  659. //} else if listType == 2 {
  660. // source = 1
  661. //} else {
  662. // source = 2
  663. //}
  664. if chartTotal > int(total) {
  665. total = int64(chartTotal)
  666. }
  667. if listType == 1 {
  668. total = total + int64(chartTotal)
  669. }
  670. if len(result) == 0 {
  671. result = make([]*models.SearchItem, 0)
  672. } else {
  673. yxArticleIdMap := services.GetYxArticleIdMap(articleIds)
  674. articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
  675. for _, v := range result {
  676. v.IsResearch = yxArticleIdMap[v.ArticleId] // 添加是否属于研选的标识
  677. v.Pv = articleMapPv[v.ArticleId] // Pv
  678. }
  679. }
  680. page := paging.GetPaging(currentIndex, pageSize, int(total))
  681. resp.Paging = page
  682. resp.List = result
  683. br.Ret = 200
  684. br.Success = true
  685. br.Msg = "获取成功"
  686. br.Data = resp
  687. }
  688. // @Title 综合搜索接口
  689. // @Description 综合搜索接口
  690. // @Param PageSize query int true "每页数据条数"
  691. // @Param CurrentIndex query int true "当前页页码,从1开始"
  692. // @Param KeyWord query string true "搜索关键词"
  693. // @Success 200 {object} models.SearchItem
  694. // @router /comprehensive/list [get]
  695. func (this *SearchController) ComprehensiveList() {
  696. br := new(models.BaseResponse).Init()
  697. defer func() {
  698. this.Data["json"] = br
  699. this.ServeJSON()
  700. }()
  701. pageSize, _ := this.GetInt("PageSize")
  702. currentIndex, _ := this.GetInt("CurrentIndex")
  703. var startSize int
  704. if pageSize <= 0 {
  705. pageSize = utils.PageSize20
  706. }
  707. if currentIndex <= 0 {
  708. currentIndex = 1
  709. }
  710. startSize = paging.StartIndex(currentIndex, pageSize)
  711. keyWord := this.GetString("KeyWord")
  712. if keyWord == "" {
  713. br.Msg = "请输入搜索词"
  714. br.ErrMsg = "请输入搜索词"
  715. return
  716. }
  717. user := this.User
  718. if user == nil {
  719. br.Msg = "请重新登录"
  720. br.Ret = 408
  721. return
  722. }
  723. resp := new(models.HomeResourceDataListResp)
  724. tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(keyWord, startSize, pageSize)
  725. if err != nil {
  726. br.Msg = "检索失败"
  727. br.ErrMsg = "检索失败,Err:" + err.Error()
  728. return
  729. }
  730. //for _, v := range tmpResult {
  731. // fmt.Println(v.Title, "Title", v.IsSummary)
  732. //}
  733. list, err := services.GetResourceDataEsList(tmpResult, user)
  734. if err != nil {
  735. br.Msg = "获取失败"
  736. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  737. return
  738. }
  739. if currentIndex == 1 {
  740. go services.AddSearchKeyWord(user, keyWord, 1)
  741. }
  742. resp.List = list
  743. page := paging.GetPaging(currentIndex, pageSize, int(tmpTotalResult))
  744. resp.Paging = page
  745. br.Ret = 200
  746. br.Success = true
  747. br.Msg = "获取成功"
  748. br.Data = resp
  749. }