logo search
This commit is contained in:
parent
615032a0a8
commit
956cbde1bc
@ -25,8 +25,33 @@ type PreLogoSearchResult struct {
|
|||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
// 搜索建议
|
// 搜索
|
||||||
func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
|
func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
|
||||||
|
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
|
||||||
|
for i, v := range keywords {
|
||||||
|
keywords[i] = "+" + v + "*"
|
||||||
|
}
|
||||||
|
sqlstr := fmt.Sprintf("SELECT id,restaurant_name,resource_url,address,zip_code,phone,website,is_branch FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) and zipcode = ? limit %d;", count)
|
||||||
|
|
||||||
|
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "), zipcode)
|
||||||
|
err = tx.Scan(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range resp {
|
||||||
|
if resp[i].RestaurantType == nil {
|
||||||
|
resp[i].RestaurantType = FsString("")
|
||||||
|
}
|
||||||
|
resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索建议
|
||||||
|
func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
|
||||||
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
|
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
|
||||||
for i, v := range keywords {
|
for i, v := range keywords {
|
||||||
keywords[i] = "+" + v + "*"
|
keywords[i] = "+" + v + "*"
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
func PreLogoSearchSuggestionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func PreLogoSearchSuggestionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.PreLogoSearchRequest
|
var req types.PreLogoSearchSuggestionsRequest
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -30,18 +30,14 @@ func NewPreLogoSearchSuggestionsLogic(ctx context.Context, svcCtx *svc.ServiceCo
|
|||||||
// func (l *PreLogoSearchSuggestionsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
// func (l *PreLogoSearchSuggestionsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *PreLogoSearchSuggestionsLogic) PreLogoSearchSuggestions(req *types.PreLogoSearchRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *PreLogoSearchSuggestionsLogic) PreLogoSearchSuggestions(req *types.PreLogoSearchSuggestionsRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
if !userinfo.IsOnlooker() {
|
if !userinfo.IsOnlooker() {
|
||||||
return resp.SetStatus(basic.CodeSearchAuthErr)
|
return resp.SetStatus(basic.CodeSearchAuthErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.ZipCode) < 4 {
|
result, err := l.svcCtx.AllModels.FsPreprocessLogo.PreLogoSearchSuggestions(l.ctx, req.Keywords, 5)
|
||||||
return resp.SetStatus(basic.CodeSearchZipCodeErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := l.svcCtx.AllModels.FsPreprocessLogo.PreLogoSearch(l.ctx, req.ZipCode, req.Keywords, 5)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatus(basic.CodeApiErr, err)
|
return resp.SetStatus(basic.CodeApiErr, err)
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ type ContactUsRequest struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PreLogoSearchSuggestionsRequest struct {
|
||||||
|
Keywords string `json:"keywords"` // 关键字
|
||||||
|
}
|
||||||
|
|
||||||
type PreLogoSearchRequest struct {
|
type PreLogoSearchRequest struct {
|
||||||
ZipCode string `json:"zip_code"` // 邮编
|
ZipCode string `json:"zip_code"` // 邮编
|
||||||
Keywords string `json:"keywords"` // 关键字
|
Keywords string `json:"keywords"` // 关键字
|
||||||
|
@ -42,7 +42,7 @@ service info {
|
|||||||
|
|
||||||
// 搜索建议
|
// 搜索建议
|
||||||
@handler PreLogoSearchSuggestionsHandler
|
@handler PreLogoSearchSuggestionsHandler
|
||||||
post /api/info/prelogo/search/suggestions(PreLogoSearchRequest) returns (response);
|
post /api/info/prelogo/search/suggestions(PreLogoSearchSuggestionsRequest) returns (response);
|
||||||
|
|
||||||
// 搜索
|
// 搜索
|
||||||
@handler PreLogoSearchHandler
|
@handler PreLogoSearchHandler
|
||||||
@ -60,6 +60,10 @@ type (
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PreLogoSearchSuggestionsRequest {
|
||||||
|
Keywords string `json:"keywords"` // 关键字
|
||||||
|
}
|
||||||
|
|
||||||
PreLogoSearchRequest {
|
PreLogoSearchRequest {
|
||||||
ZipCode string `json:"zip_code"` // 邮编
|
ZipCode string `json:"zip_code"` // 邮编
|
||||||
Keywords string `json:"keywords"` // 关键字
|
Keywords string `json:"keywords"` // 关键字
|
||||||
|
Loading…
x
Reference in New Issue
Block a user