fusenapi/model/gmodel/fs_preprocess_logo_logic.go

31 lines
796 B
Go
Raw Normal View History

2023-10-20 05:25:35 +00:00
package gmodel
import (
"context"
"fmt"
"regexp"
"strings"
2023-10-20 06:08:58 +00:00
"github.com/zeromicro/go-zero/core/logx"
2023-10-20 05:25:35 +00:00
)
// TODO: 使用model的属性做你想做的
// 搜索建议
func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []FsPreprocessLogo, err error) {
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
for i, v := range keywords {
2023-10-20 06:08:58 +00:00
keywords[i] = "+" + v + "*"
2023-10-20 05:25:35 +00:00
}
2023-10-20 06:06:36 +00:00
sqlstr := fmt.Sprintf("SELECT * FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) limit %d;", count)
2023-10-20 05:25:35 +00:00
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "))
err = tx.Scan(&resp).Error
if err != nil {
2023-10-20 06:08:58 +00:00
logx.Error(err)
2023-10-20 05:25:35 +00:00
return nil, err
}
return resp, nil
}