logo search
This commit is contained in:
		
							parent
							
								
									a3197b7d55
								
							
						
					
					
						commit
						fe5ec165f2
					
				@ -27,24 +27,34 @@ type PreLogoSearchResult struct {
 | 
			
		||||
 | 
			
		||||
// 搜索
 | 
			
		||||
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 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("")
 | 
			
		||||
	keywordsList := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
 | 
			
		||||
	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))])
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if resp == nil {
 | 
			
		||||
@ -56,24 +66,35 @@ func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode strin
 | 
			
		||||
 | 
			
		||||
// 搜索建议
 | 
			
		||||
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 + "*"
 | 
			
		||||
	}
 | 
			
		||||
	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("")
 | 
			
		||||
	keywordsList := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
 | 
			
		||||
	var keywords []string
 | 
			
		||||
	for _, v := range keywordsList {
 | 
			
		||||
		if len(v) > 1 {
 | 
			
		||||
			keywords = append(keywords, "+"+v+"*")
 | 
			
		||||
		}
 | 
			
		||||
		resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user