reply.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // ReplyRecord search reply record from ES.
  9. func (d *Dao) ReplyRecord(c context.Context, p *model.ReplyRecordParams) (res *model.SearchResult, err error) {
  10. query := elastic.NewBoolQuery()
  11. if p.Mid > 0 {
  12. query = query.Must(elastic.NewTermQuery("mid", p.Mid))
  13. } else {
  14. return
  15. }
  16. if len(p.Types) > 0 {
  17. interfaceSlice := make([]interface{}, len(p.Types))
  18. for i, d := range p.Types {
  19. interfaceSlice[i] = d
  20. }
  21. query = query.Must(elastic.NewTermsQuery("type", interfaceSlice...))
  22. }
  23. if len(p.States) > 0 {
  24. interfaceSlice := make([]interface{}, len(p.States))
  25. for i, d := range p.States {
  26. interfaceSlice[i] = d
  27. }
  28. query = query.Must(elastic.NewTermsQuery("state", interfaceSlice...))
  29. }
  30. if p.CTimeFrom != "" {
  31. query = query.Must(elastic.NewRangeQuery("ctime").Gte(p.CTimeFrom))
  32. }
  33. if p.CTimeTo != "" {
  34. query = query.Must(elastic.NewRangeQuery("ctime").Lte(p.CTimeTo))
  35. }
  36. indexName := fmt.Sprintf("replyrecord_%d", p.Mid%100)
  37. if res, err = d.searchResult(c, "replyExternal", indexName, query, p.Bsp); err != nil {
  38. PromError(fmt.Sprintf("es:%s ", p.Bsp.AppID), "%v", err)
  39. return
  40. }
  41. return
  42. }