search.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. searchMdl "go-common/app/interface/main/tv/model/search"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. const (
  8. _orderAll = "totalrank"
  9. _orderDate = "pubdate"
  10. )
  11. // searchTypes returns the ugc types
  12. func searchTypes(c *bm.Context) {
  13. c.JSON(tvSvc.SearchTypes())
  14. }
  15. // searchResult returns the result of search
  16. func searchResult(c *bm.Context) {
  17. v := new(searchMdl.ReqSearch)
  18. if err := c.Bind(v); err != nil {
  19. return
  20. }
  21. if v.Order != "" && v.Order != _orderAll && v.Order != _orderDate {
  22. c.JSON(nil, ecode.TvSearchOrderWrong)
  23. }
  24. c.JSON(secSvc.SearchRes(c, v))
  25. }
  26. // searchSug search suggestion words
  27. func searchSug(c *bm.Context) {
  28. v := new(searchMdl.ReqSug)
  29. if err := c.Bind(v); err != nil {
  30. return
  31. }
  32. data, err := secSvc.SearchSug(c, v)
  33. if err != nil {
  34. c.JSON(nil, err)
  35. return
  36. }
  37. c.JSONMap(map[string]interface{}{
  38. "result": data.Result,
  39. "message": "success",
  40. "cost": data.Cost,
  41. "stoken": data.Stoken,
  42. }, nil)
  43. }
  44. func pgcIdx(c *bm.Context) {
  45. v := new(searchMdl.ReqPgcIdx)
  46. if err := c.Bind(v); err != nil {
  47. return
  48. }
  49. c.JSON(tvSvc.EsPgcIdx(c, v))
  50. }
  51. func ugcIdx(c *bm.Context) {
  52. v := new(searchMdl.ReqUgcIdx)
  53. if err := c.Bind(v); err != nil {
  54. return
  55. }
  56. c.JSON(tvSvc.EsUgcIdx(c, v))
  57. }