dm_date.go 971 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "go-common/app/service/main/search/model"
  7. elastic "gopkg.in/olivere/elastic.v5"
  8. )
  9. func (d *Dao) DmDateSearch(c context.Context, p *model.DmDateParams) (res *model.SearchResult, err error) {
  10. query := elastic.NewBoolQuery()
  11. indexName := "dm_date_" + strings.Replace(p.Month, "-", "_", -1)
  12. if p.Bsp.KW != "" {
  13. query = query.Must(elastic.NewRegexpQuery(p.Bsp.KwFields[0], ".*"+p.Bsp.KW+".*"))
  14. }
  15. if p.Oid != -1 {
  16. query = query.Filter(elastic.NewTermQuery("oid", p.Oid))
  17. }
  18. if p.Month != "" {
  19. query = query.Filter(elastic.NewTermQuery("month", p.Month))
  20. }
  21. if p.MonthFrom != "" {
  22. query = query.Filter(elastic.NewRangeQuery("month").Gte(p.MonthFrom))
  23. }
  24. if p.MonthTo != "" {
  25. query = query.Filter(elastic.NewRangeQuery("month").Lte(p.MonthTo))
  26. }
  27. if res, err = d.searchResult(c, "dmExternal", indexName, query, p.Bsp); err != nil {
  28. PromError(fmt.Sprintf("es:%s ", p.Bsp.AppID), "%v", err)
  29. }
  30. return
  31. }