You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.4 KiB
72 lines
1.4 KiB
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
|
|
}
|
|
|