A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
update: tag add search limit
LinkinStar54115ce243a9
diff --git a/internal/base/conf/conf.go b/internal/base/conf/conf.goindex 70eb85ef..27f289f8 100644--- a/internal/base/conf/conf.go+++ b/internal/base/conf/conf.go@@ -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"`-}diff --git a/internal/repo/tag/tag_repo.go b/internal/repo/tag/tag_repo.goindex 4622a85b..a9c8699d 100644--- a/internal/repo/tag/tag_repo.go+++ b/internal/repo/tag/tag_repo.go@@ -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()diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.goindex 44747ca0..945f6356 100644--- a/internal/service/tag/tag_service.go+++ b/internal/service/tag/tag_service.go@@ -41,12 +41,11 @@ func NewTagService(// SearchTagLike get tag list allfunc (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, nildiff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.goindex ba0eee07..b76c3503 100644--- a/internal/service/tag_common/tag_common.go+++ b/internal/service/tag_common/tag_common.go@@ -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)