search_subtitle.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/database/elastic"
  6. "go-common/library/log"
  7. )
  8. var (
  9. _subtitleFields = []string{"oid", "id"}
  10. )
  11. // SearchSubtitle .
  12. func (d *Dao) SearchSubtitle(c context.Context, arg *model.SubtitleSearchArg) (res *model.SearchSubtitleResult, err error) {
  13. var (
  14. req *elastic.Request
  15. fields []string
  16. )
  17. fields = _subtitleFields
  18. req = d.esCli.NewRequest("dm_subtitle").Index("subtitle").Fields(fields...).Pn(int(arg.Pn)).Ps(int(arg.Ps))
  19. if arg.Aid > 0 {
  20. req.WhereEq("aid", arg.Aid)
  21. }
  22. if arg.Mid > 0 {
  23. req.WhereEq("mid", arg.Mid)
  24. }
  25. if arg.Oid > 0 {
  26. req.WhereEq("oid", arg.Oid)
  27. }
  28. if arg.Mid > 0 {
  29. req.WhereEq("mid", arg.Mid)
  30. }
  31. if arg.Status > 0 {
  32. req.WhereEq("status", arg.Status)
  33. }
  34. if arg.UpperMid > 0 {
  35. req.WhereEq("up_mid", arg.UpperMid)
  36. }
  37. if arg.Lan > 0 {
  38. req.WhereEq("lan", arg.Lan)
  39. }
  40. req.Order("mtime", "desc")
  41. if err = req.Scan(c, &res); err != nil {
  42. log.Error("elastic search(%s) error(%v)", req.Params(), err)
  43. return
  44. }
  45. return
  46. }