search.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/esports/model"
  5. "go-common/library/database/elastic"
  6. "go-common/library/log"
  7. )
  8. // SearchArc search archive.
  9. func (d *Dao) SearchArc(c context.Context, p *model.ArcListParam) (rs []*model.SearchArc, total int, err error) {
  10. req := d.Elastic.NewRequest(_esports).Index(_esports).Pn(p.Pn).Ps(p.Ps)
  11. req.Fields("aid", "typeid", "title", "state", "mid", "gid", "tags", "teams", "matchs", "year")
  12. if p.Title != "" {
  13. req.WhereLike([]string{"title"}, []string{p.Title}, true, elastic.LikeLevelLow)
  14. }
  15. if p.Aid > 0 {
  16. req.WhereEq("aid", p.Aid)
  17. }
  18. if p.TypeID > 0 {
  19. req.WhereEq("type_id", p.TypeID)
  20. }
  21. if p.Copyright > 0 {
  22. req.WhereEq("copyright", p.Copyright)
  23. }
  24. if p.State != "" {
  25. req.WhereEq("state", p.State)
  26. }
  27. req.WhereEq("is_deleted", 0)
  28. res := new(struct {
  29. Page struct {
  30. Num int `json:"num"`
  31. Size int `json:"size"`
  32. Total int `json:"total"`
  33. } `json:"page"`
  34. Result []*model.SearchArc `json:"result"`
  35. })
  36. if err = req.Scan(c, &res); err != nil || res == nil {
  37. log.Error("SearchArc req.Scan error(%v)", err)
  38. return
  39. }
  40. total = res.Page.Total
  41. rs = res.Result
  42. return
  43. }