package logic import ( "context" "fmt" "demo/internal/svc" "demo/internal/types" es "demo/model/es_pro" "github.com/zeromicro/go-zero/core/logx" ) type EsProSearchDistrictLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewEsProSearchDistrictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsProSearchDistrictLogic { return &EsProSearchDistrictLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *EsProSearchDistrictLogic) EsProSearchDistrict(req *types.EsProQueryName) (resp *types.Response, err error) { esQuery := ` { "query": { "bool": { "must": [ { "match_phrase": { "districtName": "%s" } }, { "match_phrase": { "year": "%s" } }, { "match_phrase": { "lotType": "%s" } }, { "match_phrase": { "districtCode": "%s" } } ] } } } ` esQueryStr := fmt.Sprintf(esQuery, req.Name, req.Year, req.LotType, req.Code) doc, err := es.EsServiceApp.EsSearchDocWithStr(l.ctx, esQueryStr, int(req.Page), int(req.Size)) if err != nil { return nil, err } return &types.Response{ Success: true, Message: "success", Result: doc, }, nil }