logo search
This commit is contained in:
@@ -25,8 +25,33 @@ type PreLogoSearchResult struct {
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
// 搜索建议
|
||||
// 搜索
|
||||
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)
|
||||
for i, v := range keywords {
|
||||
keywords[i] = "+" + v + "*"
|
||||
|
||||
Reference in New Issue
Block a user