pgc.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/main/search/model"
  6. elastic "gopkg.in/olivere/elastic.v5"
  7. )
  8. // PgcMedia .
  9. func (d *Dao) PgcMedia(c context.Context, p *model.PgcMediaParams) (res *model.SearchResult, err error) {
  10. query := elastic.NewBoolQuery()
  11. if p.Bsp.KW != "" {
  12. query = query.Must(elastic.NewMultiMatchQuery(p.Bsp.KW, "title").Type("best_fields").TieBreaker(0.3))
  13. }
  14. if len(p.MediaIds) > 0 {
  15. interfaceSlice := make([]interface{}, len(p.MediaIds))
  16. for i, d := range p.MediaIds {
  17. interfaceSlice[i] = d
  18. }
  19. query = query.Filter(elastic.NewTermsQuery("media_id", interfaceSlice...))
  20. }
  21. if len(p.SeasonIds) > 0 {
  22. interfaceSlice := make([]interface{}, len(p.SeasonIds))
  23. for i, d := range p.SeasonIds {
  24. interfaceSlice[i] = d
  25. }
  26. query = query.Filter(elastic.NewTermsQuery("season_id", interfaceSlice...))
  27. }
  28. if len(p.SeasonTypes) > 0 {
  29. interfaceSlice := make([]interface{}, len(p.SeasonTypes))
  30. for i, d := range p.SeasonTypes {
  31. interfaceSlice[i] = d
  32. }
  33. query = query.Filter(elastic.NewTermsQuery("season_type", interfaceSlice...))
  34. }
  35. if len(p.StyleIds) > 0 {
  36. interfaceSlice := make([]interface{}, len(p.StyleIds))
  37. for i, d := range p.StyleIds {
  38. interfaceSlice[i] = d
  39. }
  40. query = query.Filter(elastic.NewTermsQuery("style_id", interfaceSlice...))
  41. }
  42. if p.Status > -1000 {
  43. query = query.Filter(elastic.NewTermQuery("status", p.Status))
  44. }
  45. if p.ReleaseDateFrom != "" {
  46. query = query.Filter(elastic.NewRangeQuery("release_date").Gte(p.ReleaseDateFrom))
  47. }
  48. if p.ReleaseDateTo != "" {
  49. query = query.Filter(elastic.NewRangeQuery("release_date").Lte(p.ReleaseDateTo))
  50. }
  51. if p.ReleaseDateFrom != "" {
  52. query = query.Filter(elastic.NewRangeQuery("release_date").Gte(p.ReleaseDateFrom))
  53. }
  54. if p.ReleaseDateTo != "" {
  55. query = query.Filter(elastic.NewRangeQuery("release_date").Lte(p.ReleaseDateTo))
  56. }
  57. if p.SeasonIDFrom > 0 {
  58. query = query.Filter(elastic.NewRangeQuery("season_id").Gte(p.SeasonIDFrom))
  59. }
  60. if p.SeasonIDTo > 0 {
  61. query = query.Filter(elastic.NewRangeQuery("season_id").Lte(p.SeasonIDTo))
  62. }
  63. if len(p.ProducerIds) > 0 {
  64. interfaceSlice := make([]interface{}, len(p.ProducerIds))
  65. for i, d := range p.ProducerIds {
  66. interfaceSlice[i] = d
  67. }
  68. query = query.Filter(elastic.NewTermsQuery("producer_id", interfaceSlice...))
  69. }
  70. if p.IsDeleted == 0 {
  71. query = query.MustNot(elastic.NewTermQuery("is_deleted", 1))
  72. }
  73. if len(p.AreaIds) > 0 {
  74. interfaceSlice := make([]interface{}, len(p.AreaIds))
  75. for i, o := range p.AreaIds {
  76. interfaceSlice[i] = o
  77. }
  78. query = query.Filter(elastic.NewTermsQuery("area_id", interfaceSlice...))
  79. }
  80. if p.ScoreFrom > 0 {
  81. query = query.Filter(elastic.NewRangeQuery("score_from").Gte(p.ScoreFrom))
  82. }
  83. if p.ScoreTo > 0 {
  84. query = query.Filter(elastic.NewRangeQuery("score_to").Lte(p.ScoreTo))
  85. }
  86. if p.IsFinish != "" {
  87. query = query.Filter(elastic.NewTermsQuery("is_finish", p.IsFinish))
  88. }
  89. if len(p.SeasonVersions) > 0 {
  90. interfaceSlice := make([]interface{}, len(p.SeasonVersions))
  91. for i, o := range p.SeasonVersions {
  92. interfaceSlice[i] = o
  93. }
  94. query = query.Filter(elastic.NewTermsQuery("season_version", interfaceSlice...))
  95. }
  96. if len(p.SeasonStatuses) > 0 {
  97. interfaceSlice := make([]interface{}, len(p.SeasonStatuses))
  98. for i, o := range p.SeasonStatuses {
  99. interfaceSlice[i] = o
  100. }
  101. query = query.Filter(elastic.NewTermsQuery("season_status", interfaceSlice...))
  102. }
  103. if p.PubTimeFrom != "" {
  104. query = query.Filter(elastic.NewRangeQuery("pub_time").Gte(p.PubTimeFrom))
  105. }
  106. if p.PubTimeTo != "" {
  107. query = query.Filter(elastic.NewRangeQuery("pub_time").Lte(p.PubTimeTo))
  108. }
  109. if len(p.SeasonMonths) > 0 {
  110. interfaceSlice := make([]interface{}, len(p.SeasonMonths))
  111. for i, o := range p.SeasonMonths {
  112. interfaceSlice[i] = o
  113. }
  114. query = query.Filter(elastic.NewTermsQuery("season_month", interfaceSlice...))
  115. }
  116. if p.LatestTimeFrom != "" {
  117. query = query.Filter(elastic.NewRangeQuery("latest_time").Gte(p.LatestTimeFrom))
  118. }
  119. if p.LatestTimeTo != "" {
  120. query = query.Filter(elastic.NewRangeQuery("latest_time").Lte(p.LatestTimeTo))
  121. }
  122. if len(p.CopyrightInfos) > 0 {
  123. interfaceSlice := make([]interface{}, len(p.CopyrightInfos))
  124. for i, o := range p.CopyrightInfos {
  125. interfaceSlice[i] = o
  126. }
  127. query = query.Filter(elastic.NewTermsQuery("copyright_info", interfaceSlice...))
  128. }
  129. p.Bsp.Source = []string{"media_id", "season_id", "season_type", "dm_count", "play_count", "fav_count", "score", "latest_time", "pub_time", "release_date"}
  130. if res, err = d.searchResult(c, "externalPublic", "pgc_media", query, p.Bsp); err != nil {
  131. PromError(fmt.Sprintf("es:%s ", p.Bsp.AppID), "%v", err)
  132. }
  133. return
  134. }