28 lines
733 B
Go
28 lines
733 B
Go
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// 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 {
|
|
keywords[i] = "+" + v + v
|
|
}
|
|
sqlstr := fmt.Sprintf("SELECT * FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) limit %d;", count)
|
|
|
|
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "))
|
|
err = tx.Scan(&resp).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
|
|
}
|