197 lines
14 KiB
Go
197 lines
14 KiB
Go
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type PreLogoSearchResult struct {
|
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 自增的唯一id
|
|
RestaurantName *string `gorm:"index;default:'';" json:"restaurant_name"` //
|
|
ResourceUrl *string `gorm:"default:'';" json:"resource_url"` //
|
|
RestaurantType *string `gorm:"default:'';" json:"restaurant_type"` //
|
|
Address *string `gorm:"default:'';" json:"address"` //
|
|
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
|
Phone *string `gorm:"default:'';" json:"phone"` //
|
|
Website *string `gorm:"default:'';" json:"website"` //
|
|
IsBranch *int64 `gorm:"default:0;" json:"is_branch"` // 是否分店
|
|
}
|
|
|
|
// TODO: 使用model的属性做你想做的
|
|
|
|
// 搜索
|
|
func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
|
|
keywordsList := SplitSearchKeywords(keywordsStr)
|
|
var keywords []string
|
|
for _, v := range keywordsList {
|
|
if len(v) > 1 {
|
|
keywords = append(keywords, "+"+v+"*")
|
|
}
|
|
}
|
|
|
|
if len(keywords) != 0 {
|
|
|
|
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 zip_code = ? 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("")
|
|
}
|
|
|
|
if len(*resp[i].ResourceUrl) < 10 {
|
|
resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
|
|
}
|
|
}
|
|
}
|
|
|
|
if resp == nil {
|
|
resp = make([]PreLogoSearchResult, 0)
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
func SplitSearchKeywords(keywordsStr string) []string {
|
|
return regexp.MustCompile(`\s+|\++`).Split(keywordsStr, -1)
|
|
}
|
|
|
|
// 搜索建议
|
|
func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
|
|
// keywordsList := regexp.MustCompile(`\s+|\++`).Split(keywordsStr, -1)
|
|
keywordsList := SplitSearchKeywords(keywordsStr)
|
|
var keywords []string
|
|
for _, v := range keywordsList {
|
|
if len(v) > 1 {
|
|
keywords = append(keywords, "+"+v+"*")
|
|
}
|
|
}
|
|
|
|
if len(keywords) != 0 {
|
|
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) limit %d;", count)
|
|
|
|
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "))
|
|
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("")
|
|
}
|
|
|
|
if len(*resp[i].ResourceUrl) < 10 {
|
|
resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
resp = make([]PreLogoSearchResult, 0)
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
var testData = []string{
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7496a14fb62571d07c485a0e9de25440ff178122a4842b73f2ca49833a4ce74d",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/74ca91d9f3beaa1674832565dfa925d801c1b752703307b1205d546dff32e68b",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/75cea2f3993c39f19fe48f1cebb55c83049155fada1397e98a18f5f9c8a647d5",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7657923837e118644fd76d68c8238384c8c29156d2d84f243fd638386c9a6d32",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/76a86fd26acfa828cec89300da307cd83cbf785fb6b6af92afeb18192532ea13",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/78315df91146c77242314d22014083c764f336ba7abd89115eb02001c779e926",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/78feef6e8429e5121ebb160e7229402a3ec121a958c75f9ede07f730f6f25711",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7909c8e6485f3a908105aeb499bd07c6ca18feaca0fd724aac7b4f2d127735ca",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7a5e04ba33105a3935e808e8dcde12a2d793409d7e8b7f7ef465801ae92b982d",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7ad3beb80d268fdda4f312d25e3bc1721c00ef0d1badc133df03f38217c8c207",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7c5f51a90444edc1edf673904d11771f1c43930a9f28de2c42a1bf1164a73ade",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7d072fa805ae0e260e0619cda11ace59233adc4cc8bc63e2017013817dce5011",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7d34b57d47f4faea05ad6ba8ef73d9815fbaf048e945e85e7e36d7c26b02151b",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/7fa3df13072e3fb0e47904be65109526bfb21db795c53cabae8625758135aa6c",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/802f96696e5b8a4fb5ef90bc812cde7ff50e54125d7e8439159a66da9a512bf5",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/81e9384055c708098bf4dfca893d7b39ba94444d980b87ee74385c7e01b94c6f",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/83352df2db64d50efc36d972dd01035a79edca77e7360dd486366fecf5799336",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/83b496eae54768a82c3a828d33e544bfaf46544977371eb8cc7dfdb3d43e453d",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/84e130d75a4cf3e27f1f3851395c75341a171053a42e93ae1a7b69c3e7cf58ad",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8505e9775556ee4d9fd03478098f73cbb9ccfdb3567d5cadc2ada7c43d2150df",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/864c84568b4816fbc29814d38b3bf079aba5a35b5d07f5b57f3dd2a79409b204",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/870446c5543c74cb351696713d4ff85a20a17ea9186da9b4c0bf6db3d6217a7c",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/88e1b79804a776272007a64da435e4a7bfee5d2693da8479f31c79036d45eec8",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/88f7e10f711d726c52fad4e6d378b0ed814067477a3564ed6601c98b9d98fb4c",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8908471ae4ff7b0ac405952d6bc2bd049af0cbff7fd892762076f5ed19a34cee",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/899fb5321402c8f562f072993f81ad22edb3df2feb43c2436e92cb4b97036caa",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8c59b2714ff399f394cc2e728766c2f0b07fc6d39bf090e4fea3c4f344c40508",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8cfcd0cbb8d11707dceb45f0936b8c3c7b6c30f434313c252d22b7629ee72b98",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8d47deacf2960de77ddaf742a3ea8b8c7ea4b40afbf5b4e3652e78973800aeef",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/8f61f8d08c2cbf8b7e45450321037b1c51ae2a16547f8662bbb5c27e82defe84",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/922915f7ab94113afbe287feb1ddcc8a77840ee4b455e818bcef48ac35069818",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/923745c708fc1507d89c42fe3a47424bc89297754c3ff88a261abab0a59e4b8d",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/92a2fd97d6fa5385ff6bf5d64e8467331e32286fe8b179d020baf7674612e2e1",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/92f93ee2fa364b98ea13f0fe3dcf57e55ae939784ccb5489143deb6d2181ea09",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/937615ffe810ec1210d6ac9bc9671b04be4254046ded12264189637282adaa11",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/93b00364dcfd3b9f6d927eccdc65e10e293876cc0b859c0e1af35cb97343d3e4",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/93b4d14bbcf86743699825adac5bbefb737403061fceea2f8ce23027101a9b08",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/957fc76c9c84d6cc177ba1e7d92913a3fdcade6c5501103d7a39b743affd6451",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/958454c580e5708e2ca704893bc31196a8cf68dccca6549ded063e708e59b9a0",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/95bf354437c8c36bcc34979b81006586c3abcc8cbbd13b277fb8539d817a0400",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/95f6d1152a481e19f641272c4f0ef046b383abc8286e3b2ac329cc1558cd2453",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/96813af51fbc66556a5b616e4964434bac5fbdd5faccbd8c147727f0838b266f",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/96e1911af7a506c30c8d1d5a0df6ea7a20a7030fe5f43e26097e1c241e5688bf",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/97589c622074193c4f85afb5041b7fdaa22cde42c878520f190ac657e71bb257",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/98ce764aaf1021f8caf54eb299decaa28839b55bb7ee769804cb7e5ea942a051",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/98f7a95879da3ebe551c8a4484faaa3a3801ef9beb2129b1f1c450149768f28a",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/99ebccb5fe9d7c985bc4ea1cd1f0b9681ee8e4225a422f14c2efc0432b7adc09",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9b559c125a353299331068eb3d7bd5f41c8b922644725dc3df60c3a1a53763b3",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9b8c409168efe89e7b78437d1622f726b7a75c517c4386c30cbff4811665ad86",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9c246614316fe1727a5b36dc428876ac6f1d6424e8ce4feb51d9b6f8b363d39d",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9caf9bd0676e696bc5c0735498a50f2281941bc59ec323d96cfe2536096bdf50",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9d0594ca037f3998681a3f2458a954f1ecb2b4bd7f3dabcc304adc4d9ba452aa",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9d5809781f3f3e284add2a6e2e79965f0e1930744f8264f8e73750c05d3d4b20",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9ef6ded5b910985f35dc6cba469cb5eb20626b07ed6bca449261cc1d8f8147cf",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9f0cc4bf9f3a5642b1510b5a6a911c53f8f2664071dfcbd9239d160a6fb02d32",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/9f91ada7ebc9a2bf623881a2daed0643a81785d2d7624738c3b6bb17cffa58a7",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a26d27fbf27bdd4ab76cefe46a337326432435fc36cce5e5f5e2499e22642f13",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a36543d0d6ee8435bf0ba18ab96fc424c52649a737502f663efd4fc128aaed22",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a4cb2e6c0d93adfb6ebc6c03820dc3dd4b2e5a6bf737782fc910502e5f78d6b7",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a5861470cc5dc7f23a0a66022301fe46a7cf5bf78aa4cbb8aff96bfe1a792220",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a6dbc806559141970a2309c3e20fa019d112eb76c96badc2b99e43c0e19ab17f",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a72eb76e76a2627f8532bc96d8111f22b7132e32795effc628b1acab0a31e8fb",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a827d4012554ea3be1ce1cc86c56d10bb43fa80d6d5e36be5c7ce5ef232e5757",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a93b38fdaf20bddb560ee6a9eb7c2ddf34b3480a771533fe3343905b4e05e4a8",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/a9f540186a6e9ecf5dae469e83cd952fd0d1539798edf5c7690af858efbb8cbf",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/ab1326e69ff13289c9ac00deac7d61a581a10580e701ff61fe9065937c2c7f11",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/abda7e2720063f576fbf3ada356a721a183c0548e11b1878d414de733cf3754e",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/abecd9297af902c0ec32350f4710b4ed6c4c596d6b24228314a833c95993aa94",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/ad4a15c1eaa714e6481812ac938ab09a5f47de116ae8880353be6e12ba8eb64a",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/ad677b423fee3d9a1fe3aee24dc00255b5ff0e266fcd0bbca1c2098a2712d91b",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/af0a5621c098fe437a419215105d0485603a27dfdf697df85b966c00fc45b7c8",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/af4d0f94627384bc66fda949052bc1db8d945c1f8e6dcea71dd3d35a011323a0",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/afad479690db35e8371cce3dceae13bfff06fff1a9c0b3487ae6f830e984e416",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b33574c05de24f5963e14813345c601663d66e1db4fedc840b728248e15e1992",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b3723604352d76aa3d6aee1db3cdfd96c3141926f5565efd8d7f7881cfe11ece",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b390c9c5456a1f97e743b2166de1c0dce56e582e4f2b32a0b7aaf842438aafb3",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b420ec89935d2b243600537096046d45bd4ecf071133accd9bd727f92916d442",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b656b871d6663fe0c180c25a001c3e7f0195e4b3e665cee0d52593ccd65a7ec1",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b698198af640aaf742371a873abe537993b086282c153705b65b7244aeccf154",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b95d2daf610d90098669f10b315b89765b011aec63ebac14e2a4aef68ed5fadb",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b976f1c46cf74753948bec7eb623cc0eb9235c1160f9677a31884bd34521a759",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/ba529a80062844e682f545f5ba50d75ba53ffd59a6ebb0531c962e5c45122846",
|
|
"https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/bb2652012232cf15c52ab370ae5608621850577369242d9dff0e0f3dbebdab14",
|
|
}
|