search.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. if listType == 1 || listType == 2 {
  583. tmpResult, tmpTotal, tmpErr := services.EsArticleSearch(keyWord, startSize, pageSize, orderColumn)
  584. result = tmpResult
  585. total = tmpTotal
  586. err = tmpErr
  587. if err != nil {
  588. br.Msg = "检索失败"
  589. br.ErrMsg = "检索失败,Err:" + err.Error()
  590. return
  591. }
  592. if len(result) == 0 {
  593. result = make([]*models.SearchItem, 0)
  594. }
  595. for k, v := range result {
  596. //如果是研选系列的任意取五张图片的中的一张
  597. if v.CategoryId == "0" {
  598. knum := v.ArticleId % 5
  599. result[k].ImgUrlPc = researchList[knum]
  600. } else {
  601. result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  602. }
  603. result[k].Source = 1
  604. }
  605. }
  606. //记录用户搜索关键词
  607. var source int
  608. if listType == 1 {
  609. source = 3
  610. } else if listType == 2 {
  611. source = 1
  612. } else {
  613. source = 2
  614. }
  615. go services.AddSearchKeyWord(user, keyWord, source)
  616. if chartTotal > int(total) {
  617. total = int64(chartTotal)
  618. }
  619. if listType == 1 {
  620. total = total + int64(chartTotal)
  621. }
  622. if len(result) == 0 {
  623. result = make([]*models.SearchItem, 0)
  624. }
  625. page := paging.GetPaging(currentIndex, pageSize, int(total))
  626. resp.Paging = page
  627. resp.List = result
  628. br.Ret = 200
  629. br.Success = true
  630. br.Msg = "获取成功"
  631. br.Data = resp
  632. }