mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/tag/search' into 'main'
update: tag add search limit See merge request opensource/answer!27
This commit is contained in:
commit
5039569e94
|
@ -28,44 +28,3 @@ type Data struct {
|
|||
Database *data.Database `json:"database" mapstructure:"database"`
|
||||
Cache *data.CacheConf `json:"cache" mapstructure:"cache"`
|
||||
}
|
||||
|
||||
// ------------------ remove
|
||||
|
||||
// log .
|
||||
type log struct {
|
||||
Dir string `json:"dir"`
|
||||
Name string `json:"name"`
|
||||
Access bool `json:"access"`
|
||||
Level string `json:"level"`
|
||||
MaxSize int `json:"max_size"`
|
||||
MaxBackups int `json:"max_backups"`
|
||||
MaxAge int `json:"max_age"`
|
||||
}
|
||||
|
||||
// Local .
|
||||
type Local struct {
|
||||
Address string `json:"address"`
|
||||
Debug bool `json:"debug"`
|
||||
log log `json:"log"`
|
||||
}
|
||||
|
||||
// // SwaggerConfig .
|
||||
// type SwaggerConfig struct {
|
||||
// Show bool `json:"show"`
|
||||
// Protocol string `json:"protocol"`
|
||||
// Host string `json:"host"`
|
||||
// Address string `json:"address"`
|
||||
// }
|
||||
|
||||
// Answer .
|
||||
type Answer struct {
|
||||
MaxIdle int `json:"max_idle"`
|
||||
MaxOpen int `json:"max_open"`
|
||||
IsDebug bool `json:"is_debug"`
|
||||
Datasource string `json:"datasource"`
|
||||
}
|
||||
|
||||
// Mysql .
|
||||
type Mysql struct {
|
||||
Answer Answer `json:"answer"`
|
||||
}
|
||||
|
|
|
@ -73,10 +73,11 @@ func (tr *tagRepo) GetTagBySlugName(ctx context.Context, slugName string) (tagIn
|
|||
}
|
||||
|
||||
// GetTagListByName get tag list all like name
|
||||
func (tr *tagRepo) GetTagListByName(ctx context.Context, name string) (tagList []*entity.Tag, err error) {
|
||||
func (tr *tagRepo) GetTagListByName(ctx context.Context, name string, limit int) (tagList []*entity.Tag, err error) {
|
||||
tagList = make([]*entity.Tag, 0)
|
||||
session := tr.data.DB.Where(builder.Like{"slug_name", name})
|
||||
session := tr.data.DB.Where("LIKE ?", name+"%")
|
||||
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
|
||||
session.Limit(limit).Asc("slug_name")
|
||||
err = session.Find(&tagList)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
|
|
@ -41,12 +41,11 @@ func NewTagService(
|
|||
|
||||
// SearchTagLike get tag list all
|
||||
func (ts *TagService) SearchTagLike(ctx context.Context, req *schema.SearchTagLikeReq) (resp []string, err error) {
|
||||
tags, err := ts.tagRepo.GetTagListByName(ctx, req.Tag)
|
||||
tags, err := ts.tagRepo.GetTagListByName(ctx, req.Tag, 5)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, tag := range tags {
|
||||
//resp = append(resp, tag.DisplayName)
|
||||
resp = append(resp, tag.SlugName)
|
||||
}
|
||||
return resp, nil
|
||||
|
|
|
@ -16,7 +16,7 @@ type TagRepo interface {
|
|||
AddTagList(ctx context.Context, tagList []*entity.Tag) (err error)
|
||||
GetTagListByIDs(ctx context.Context, ids []string) (tagList []*entity.Tag, err error)
|
||||
GetTagBySlugName(ctx context.Context, slugName string) (tagInfo *entity.Tag, exist bool, err error)
|
||||
GetTagListByName(ctx context.Context, name string) (tagList []*entity.Tag, err error)
|
||||
GetTagListByName(ctx context.Context, name string, limit int) (tagList []*entity.Tag, err error)
|
||||
GetTagListByNames(ctx context.Context, names []string) (tagList []*entity.Tag, err error)
|
||||
RemoveTag(ctx context.Context, tagID string) (err error)
|
||||
UpdateTag(ctx context.Context, tag *entity.Tag) (err error)
|
||||
|
|
Loading…
Reference in New Issue