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.
fix: search sort
kumfo01bfa95962e4
diff --git a/docs/docs.go b/docs/docs.goindex b114aa17..d0ecc7d0 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -2589,6 +2589,18 @@ const docTemplate = `{"name": "q","in": "query","required": true+ },+ {+ "enum": [+ "newest",+ "active",+ "score"+ ],+ "type": "string",+ "description": "order",+ "name": "order",+ "in": "query",+ "required": true}],"responses": {@@ -5127,6 +5139,10 @@ const docTemplate = `{"id": {"type": "string"},+ "status": {+ "description": "Status",+ "type": "string"+ },"tags": {"description": "tags","type": "array",diff --git a/docs/swagger.json b/docs/swagger.jsonindex 5e186a46..fda881be 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -2577,6 +2577,18 @@"name": "q","in": "query","required": true+ },+ {+ "enum": [+ "newest",+ "active",+ "score"+ ],+ "type": "string",+ "description": "order",+ "name": "order",+ "in": "query",+ "required": true}],"responses": {@@ -5115,6 +5127,10 @@"id": {"type": "string"},+ "status": {+ "description": "Status",+ "type": "string"+ },"tags": {"description": "tags","type": "array",diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex 3d116152..b13a2092 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -939,6 +939,9 @@ definitions:type: stringid:type: string+ status:+ description: Status+ type: stringtags:description: tagsitems:@@ -2922,6 +2925,15 @@ paths:name: qrequired: truetype: string+ - description: order+ enum:+ - newest+ - active+ - score+ in: query+ name: order+ required: true+ type: stringproduces:- application/jsonresponses:diff --git a/go.mod b/go.modindex 2ebab9eb..d66332bf 100644--- a/go.mod+++ b/go.mod@@ -5,7 +5,6 @@ go 1.18require (github.com/Chain-Zhang/pinyin v0.1.3github.com/bwmarrin/snowflake v0.3.0- github.com/davecgh/go-spew v1.1.1github.com/gin-gonic/gin v1.8.1github.com/go-playground/locales v0.14.0github.com/go-playground/universal-translator v0.18.0@@ -37,6 +36,7 @@ require (require (github.com/KyleBanks/depth v1.2.1 // indirect+ github.com/davecgh/go-spew v1.1.1 // indirectgithub.com/fsnotify/fsnotify v1.5.4 // indirectgithub.com/gin-contrib/sse v0.1.0 // indirectgithub.com/go-openapi/jsonpointer v0.19.5 // indirectdiff --git a/go.sum b/go.sumindex e0e283a8..568fb36d 100644--- a/go.sum+++ b/go.sum@@ -523,24 +523,14 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhgithub.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=github.com/segmentfault/pacman v1.0.1 h1:GFdvPtNxvVVjnDM4ty02D/+4unHwG9PmjcOZSc2wRXE=github.com/segmentfault/pacman v1.0.1/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=-github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220926035018-18f894415e5b h1:jSnRy3z3KVtVuGM2YTZihXwc4zEhW+TvyyJbBm8rjh4=-github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220926035018-18f894415e5b/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347 h1:0xWBBXHHuemzMY61KYJXh7F5FW/4K8g98RYKNXodTCc=github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=-github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220926035018-18f894415e5b h1:Gx3Brm+VMAyBJn4aBsxgKl+EIhFHc/YH5cLGeFHAW4g=-github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220926035018-18f894415e5b/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220929065758-260b3093a347 h1:WpnEbmZFE8FYIgvseX+NJtDgGJlM1KSaKJhoxJywUgo=github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220929065758-260b3093a347/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=-github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220926035018-18f894415e5b h1:uQmSgcV2w4OVXU6l3bQb9O+cSAVuzDQ9adJArQyFBa4=-github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220926035018-18f894415e5b/go.mod h1:5Afm+OQdau/HQqSOp/ALlSUp0vZsMMMbv//kJhxuoi8=github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220929065758-260b3093a347 h1:Q29Ky9ZUGhdLIygfX6jwPYeEa7Wqn8o3f1NJWb8LvvE=github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220929065758-260b3093a347/go.mod h1:5Afm+OQdau/HQqSOp/ALlSUp0vZsMMMbv//kJhxuoi8=-github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220926035018-18f894415e5b h1:TaOBmAglooq+qKdnNTK2sy11t26ud7psHFB7/AV7l5U=-github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220926035018-18f894415e5b/go.mod h1:L4GqtXLoR73obTYqUQIzfkm8NG8pvZafxFb6KZFSSHk=github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220929065758-260b3093a347 h1:7Adjc296AKv32dg88S0T8t9K3+N+PFYLSCctpPnCUr0=github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220929065758-260b3093a347/go.mod h1:L4GqtXLoR73obTYqUQIzfkm8NG8pvZafxFb6KZFSSHk=-github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220926035018-18f894415e5b h1:n5n5VPeYGuZCmVppKPgWR/CaINHnL+ipEp9iE1XkcQc=-github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220926035018-18f894415e5b/go.mod h1:UjNiOFYv1uGCq1ZCcONaKq4eE7MW3nbgpLqgl8f9N40=github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220929065758-260b3093a347 h1:CfuRhTPK2CBQIZruq5ceuTVthspe8U1FDjWXXI2RWdo=github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220929065758-260b3093a347/go.mod h1:UjNiOFYv1uGCq1ZCcONaKq4eE7MW3nbgpLqgl8f9N40=github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=@@ -740,8 +730,6 @@ golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=-golang.org/x/net v0.0.0-20220926192436-02166a98028e h1:I51lVG9ykW5AQeTE50sJ0+gJCAF0J78Hf1+1VUCGxDI=-golang.org/x/net v0.0.0-20220926192436-02166a98028e/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=golang.org/x/net v0.0.0-20220927171203-f486391704dc h1:FxpXZdoBqT8RjqTy6i1E8nXHhW21wK7ptQ/EPIGxzPQ=golang.org/x/net v0.0.0-20220927171203-f486391704dc/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=@@ -824,8 +812,6 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBcgolang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=-golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 h1:nwzwVf0l2Y/lkov/+IYgMMbFyI+QypZDds9RxlSmsFQ=-golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=diff --git a/internal/controller/search_controller.go b/internal/controller/search_controller.goindex 5835008d..bcebac48 100644--- a/internal/controller/search_controller.go+++ b/internal/controller/search_controller.go@@ -28,15 +28,17 @@ func NewSearchController(searchService *service.SearchService) *SearchController// @Produce json// @Security ApiKeyAuth// @Param q query string true "query string"+// @Param order query string true "order" Enums(newest,active,score)// @Success 200 {object} handler.RespBody{data=schema.SearchListResp}// @Router /answer/api/v1/search [get]func (sc *SearchController) Search(ctx *gin.Context) {var (- q string- page string+ q,+ order,+ page,size string- ok bool- dto schema.SearchDTO+ ok bool+ dto schema.SearchDTO)q, ok = ctx.GetQuery("q")if len(q) == 0 || !ok {@@ -51,12 +53,17 @@ func (sc *SearchController) Search(ctx *gin.Context) {if !ok {size = "30"}+ order, ok = ctx.GetQuery("order")+ if !ok || (order != "newest" && order != "active" && order != "score") {+ order = "newest"+ }dto = schema.SearchDTO{Query: q,Page: converter.StringToInt(page),Size: converter.StringToInt(size),UserID: middleware.GetLoginUserIDFromContext(ctx),+ Order: order,}resp, total, extra, err := sc.searchService.Search(ctx, &dto)diff --git a/internal/repo/search_repo.go b/internal/repo/search_repo.goindex 3d1649b7..80e7804a 100644--- a/internal/repo/search_repo.go+++ b/internal/repo/search_repo.go@@ -2,6 +2,7 @@ package repoimport ("context"+ "github.com/segmentfault/pacman/log""strings""time"@@ -35,7 +36,7 @@ func NewSearchRepo(data *data.Data, uniqueIDRepo unique.UniqueIDRepo, userCommon}}-func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID, userID string, votes int, page, size int) (resp []schema.SearchResp, total int64, err error) {+func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID, userID string, votes int, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {var (b *builder.Builderub *builder.Builder@@ -51,6 +52,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,"`answer_count`","0 as `accepted`","`question`.`status` as `status`",+ "`post_update_time`",).From("`question`")ub = builder.Select("`answer`.`id` as `id`",@@ -63,6 +65,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,"0 as `answer_count`","`adopted` as `accepted`","`answer`.`status` as `status`",+ "`answer`.`created_at` as `post_update_time`",).From("`answer`").LeftJoin("`question`", "`question`.id = `answer`.question_id")@@ -103,7 +106,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,return}- res, err := sr.data.DB.OrderBy("created_at DESC").Limit(size, page).Query(b)+ res, err := sr.data.DB.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page).Query(b)tr, err := sr.data.DB.Query(builder.Select("count(*) total").From(b, "c"))if len(tr) != 0 {@@ -118,7 +121,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,}}-func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limitNoAccepted bool, answers, page, size int) (resp []schema.SearchResp, total int64, err error) {+func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limitNoAccepted bool, answers, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {b := builder.Select("`id`","`id` as `question_id`",@@ -130,6 +133,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limit"`answer_count`","0 as `accepted`","`status`",+ "`post_update_time`",).From("question")for i, word := range words {@@ -151,7 +155,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limitb.And(builder.Gte{"answer_count": answers})}- res, err := sr.data.DB.OrderBy("created_at DESC").Limit(size, page).Query(b)+ res, err := sr.data.DB.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page).Query(b)tr, err := sr.data.DB.Query(builder.Select("count(*) total").From(b, "c"))if len(tr) != 0 {@@ -168,7 +172,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limitreturn}-func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAccepted bool, questionID string, page, size int) (resp []schema.SearchResp, total int64, err error) {+func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAccepted bool, questionID string, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {b := builder.Select("`answer`.`id` as `id`","`question_id`",@@ -180,6 +184,7 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAc"0 as `answer_count`","`adopted` as `accepted`","`answer`.`status` as `status`",+ "`answer`.`created_at` as `post_update_time`",).From("`answer`").LeftJoin("`question`", "`question`.id = `answer`.question_id")@@ -199,7 +204,7 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAcb.Where(builder.Eq{"question_id": questionID})}- res, err := sr.data.DB.OrderBy("created_at DESC").Limit(size, page).Query(b)+ res, err := sr.data.DB.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page).Query(b)tr, err := sr.data.DB.Query(builder.Select("count(*) total").From(b, "c"))total = converter.StringToInt64(string(tr[0]["total"]))@@ -214,6 +219,21 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAcreturn}+func (sr *searchRepo) parseOrder(ctx context.Context, order string) (res string) {+ switch order {+ case "newest":+ res = "created_at desc"+ case "active":+ res = "post_update_time desc"+ case "score":+ res = "vote_count desc"+ default:+ res = "created_at desc"+ }+ log.Error(order, "\n", res)+ return+}+func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte) (resp []schema.SearchResp, err error) {for _, r := range res {var (diff --git a/internal/schema/search_schema.go b/internal/schema/search_schema.goindex 94958d19..a75ead91 100644--- a/internal/schema/search_schema.go+++ b/internal/schema/search_schema.go@@ -7,6 +7,7 @@ type SearchDTO struct {UserID stringPage intSize int+ Order string}type SearchObject struct {diff --git a/internal/service/search/accepted_answer.go b/internal/service/search/accepted_answer.goindex 3928e81e..f9f86f66 100644--- a/internal/service/search/accepted_answer.go+++ b/internal/service/search/accepted_answer.go@@ -9,10 +9,11 @@ import ()type AcceptedAnswerSearch struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewAcceptedAnswerSearch(repo search_common.SearchRepo) *AcceptedAnswerSearch {@@ -40,6 +41,7 @@ func (s *AcceptedAnswerSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *AcceptedAnswerSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -49,5 +51,5 @@ func (s *AcceptedAnswerSearch) Search(ctx context.Context) (resp []schema.Searchwords = words[:4]}- return s.repo.SearchAnswers(ctx, words, true, "", s.page, s.size)+ return s.repo.SearchAnswers(ctx, words, true, "", s.page, s.size, s.order)}diff --git a/internal/service/search/answer.go b/internal/service/search/answer.goindex 2a33a686..fbac8dbb 100644--- a/internal/service/search/answer.go+++ b/internal/service/search/answer.go@@ -8,10 +8,11 @@ import ()type AnswerSearch struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewAnswerSearch(repo search_common.SearchRepo) *AnswerSearch {@@ -39,6 +40,7 @@ func (s *AnswerSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *AnswerSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -48,5 +50,5 @@ func (s *AnswerSearch) Search(ctx context.Context) (resp []schema.SearchResp, towords = words[:4]}- return s.repo.SearchAnswers(ctx, words, false, "", s.page, s.size)+ return s.repo.SearchAnswers(ctx, words, false, "", s.page, s.size, s.order)}diff --git a/internal/service/search/answers.go b/internal/service/search/answers.goindex 0fe5e053..36ca50c6 100644--- a/internal/service/search/answers.go+++ b/internal/service/search/answers.go@@ -11,11 +11,12 @@ import ()type AnswersSearch struct {- repo search_common.SearchRepo- exp int- w string- page int- size int+ repo search_common.SearchRepo+ exp int+ w string+ page int+ size int+ order string}func NewAnswersSearch(repo search_common.SearchRepo) *AnswersSearch {@@ -49,6 +50,7 @@ func (s *AnswersSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}@@ -59,5 +61,5 @@ func (s *AnswersSearch) Search(ctx context.Context) (resp []schema.SearchResp, twords = words[:4]}- return s.repo.SearchQuestions(ctx, words, false, s.exp, s.page, s.size)+ return s.repo.SearchQuestions(ctx, words, false, s.exp, s.page, s.size, s.order)}diff --git a/internal/service/search/author.go b/internal/service/search/author.goindex e25f1087..0deedae3 100644--- a/internal/service/search/author.go+++ b/internal/service/search/author.go@@ -17,6 +17,7 @@ type AuthorSearch struct {w stringpage intsize int+ order string}func NewAuthorSearch(repo search_common.SearchRepo, userCommon *usercommon.UserCommon) *AuthorSearch {@@ -65,6 +66,7 @@ func (s *AuthorSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = ws.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}@@ -82,7 +84,7 @@ func (s *AuthorSearch) Search(ctx context.Context) (resp []schema.SearchResp, towords = words[:4]}- resp, total, err = s.repo.SearchContents(ctx, words, "", s.exp, -1, s.page, s.size)+ resp, total, err = s.repo.SearchContents(ctx, words, "", s.exp, -1, s.page, s.size, s.order)return}diff --git a/internal/service/search/in_question.go b/internal/service/search/in_question.goindex 2483daf2..00e24dcf 100644--- a/internal/service/search/in_question.go+++ b/internal/service/search/in_question.go@@ -9,11 +9,12 @@ import ()type InQuestionSearch struct {- repo search_common.SearchRepo- w string- exp string- page int- size int+ repo search_common.SearchRepo+ w string+ exp string+ page int+ size int+ order string}func NewInQuestionSearch(repo search_common.SearchRepo) *InQuestionSearch {@@ -47,6 +48,7 @@ func (s *InQuestionSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *InQuestionSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -59,5 +61,5 @@ func (s *InQuestionSearch) Search(ctx context.Context) (resp []schema.SearchRespwords = words[:4]}- return s.repo.SearchAnswers(ctx, words, false, s.exp, s.page, s.size)+ return s.repo.SearchAnswers(ctx, words, false, s.exp, s.page, s.size, s.order)}diff --git a/internal/service/search/not_accepted_question.go b/internal/service/search/not_accepted_question.goindex 320a8f58..9609dc42 100644--- a/internal/service/search/not_accepted_question.go+++ b/internal/service/search/not_accepted_question.go@@ -9,10 +9,11 @@ import ()type NotAcceptedQuestion struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewNotAcceptedQuestion(repo search_common.SearchRepo) *NotAcceptedQuestion {@@ -40,6 +41,7 @@ func (s *NotAcceptedQuestion) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *NotAcceptedQuestion) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -52,5 +54,5 @@ func (s *NotAcceptedQuestion) Search(ctx context.Context) (resp []schema.SearchRwords = words[:4]}- return s.repo.SearchQuestions(ctx, words, true, -1, s.page, s.size)+ return s.repo.SearchQuestions(ctx, words, true, -1, s.page, s.size, s.order)}diff --git a/internal/service/search/object.go b/internal/service/search/object.goindex 2b0c63be..abb79363 100644--- a/internal/service/search/object.go+++ b/internal/service/search/object.go@@ -9,10 +9,11 @@ import ()type ObjectSearch struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewObjectSearch(repo search_common.SearchRepo) *ObjectSearch {@@ -33,6 +34,7 @@ func (s *ObjectSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = ws.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *ObjectSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -41,5 +43,5 @@ func (s *ObjectSearch) Search(ctx context.Context) (resp []schema.SearchResp, toif len(words) > 3 {words = words[:4]}- return s.repo.SearchContents(ctx, words, "", "", -1, s.page, s.size)+ return s.repo.SearchContents(ctx, words, "", "", -1, s.page, s.size, s.order)}diff --git a/internal/service/search/question.go b/internal/service/search/question.goindex ba107493..30c914b7 100644--- a/internal/service/search/question.go+++ b/internal/service/search/question.go@@ -8,10 +8,11 @@ import ()type QuestionSearch struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewQuestionSearch(repo search_common.SearchRepo) *QuestionSearch {@@ -39,6 +40,7 @@ func (s *QuestionSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = strings.TrimSpace(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}@@ -49,5 +51,5 @@ func (s *QuestionSearch) Search(ctx context.Context) (resp []schema.SearchResp,words = words[:4]}- return s.repo.SearchQuestions(ctx, words, false, -1, s.page, s.size)+ return s.repo.SearchQuestions(ctx, words, false, -1, s.page, s.size, s.order)}diff --git a/internal/service/search/score.go b/internal/service/search/score.goindex 7a5f31fb..25e626ad 100644--- a/internal/service/search/score.go+++ b/internal/service/search/score.go@@ -11,11 +11,12 @@ import ()type ScoreSearch struct {- repo search_common.SearchRepo- exp int- w string- page int- size int+ repo search_common.SearchRepo+ exp int+ w string+ page int+ size int+ order string}func NewScoreSearch(repo search_common.SearchRepo) *ScoreSearch {@@ -44,6 +45,7 @@ func (s *ScoreSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = ws.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *ScoreSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {@@ -56,6 +58,6 @@ func (s *ScoreSearch) Search(ctx context.Context) (resp []schema.SearchResp, totwords = words[:4]}- resp, total, err = s.repo.SearchContents(ctx, words, "", "", s.exp, s.page, s.size)+ resp, total, err = s.repo.SearchContents(ctx, words, "", "", s.exp, s.page, s.size, s.order)return}diff --git a/internal/service/search/tag.go b/internal/service/search/tag.goindex 90f62304..060a8974 100644--- a/internal/service/search/tag.go+++ b/internal/service/search/tag.go@@ -21,6 +21,7 @@ type TagSearch struct {w stringuserID stringExtra schema.GetTagPageResp+ order string}func NewTagSearch(repo search_common.SearchRepo, tagRepo tagcommon.TagRepo, followCommon activity_common.FollowRepo) *TagSearch {@@ -53,6 +54,7 @@ func (ts *TagSearch) Parse(dto *schema.SearchDTO) (ok bool) {ts.page = dto.Pagets.size = dto.Sizets.userID = dto.UserID+ ts.order = dto.Orderreturn ok}@@ -90,7 +92,7 @@ func (ts *TagSearch) Search(ctx context.Context) (resp []schema.SearchResp, totawords = words[:4]}- resp, total, err = ts.repo.SearchContents(ctx, words, tag.ID, "", -1, ts.page, ts.size)+ resp, total, err = ts.repo.SearchContents(ctx, words, tag.ID, "", -1, ts.page, ts.size, ts.order)return}diff --git a/internal/service/search/views.go b/internal/service/search/views.goindex c2366cbb..ba16873d 100644--- a/internal/service/search/views.go+++ b/internal/service/search/views.go@@ -9,9 +9,10 @@ import ()type ViewsSearch struct {- repo search_common.SearchRepo- exp string- q string+ repo search_common.SearchRepo+ exp string+ q string+ order string}func NewViewsSearch(repo search_common.SearchRepo) *ViewsSearch {@@ -38,6 +39,7 @@ func (s *ViewsSearch) Parse(dto *schema.SearchDTO) (ok bool) {q = strings.TrimSpace(q)s.exp = exps.q = q+ s.order = dto.Orderreturn}func (s *ViewsSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {diff --git a/internal/service/search/within.go b/internal/service/search/within.goindex 80a96eab..5e194189 100644--- a/internal/service/search/within.go+++ b/internal/service/search/within.go@@ -8,10 +8,11 @@ import ()type WithinSearch struct {- repo search_common.SearchRepo- w string- page int- size int+ repo search_common.SearchRepo+ w string+ page int+ size int+ order string}func NewWithinSearch(repo search_common.SearchRepo) *WithinSearch {@@ -49,9 +50,10 @@ func (s *WithinSearch) Parse(dto *schema.SearchDTO) (ok bool) {s.w = string(w)s.page = dto.Pages.size = dto.Size+ s.order = dto.Orderreturn}func (s *WithinSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {- return s.repo.SearchContents(ctx, []string{s.w}, "", "", -1, s.page, s.size)+ return s.repo.SearchContents(ctx, []string{s.w}, "", "", -1, s.page, s.size, s.order)}diff --git a/internal/service/search_common/search.go b/internal/service/search_common/search.goindex 7b9634ba..de63249f 100644--- a/internal/service/search_common/search.go+++ b/internal/service/search_common/search.go@@ -6,7 +6,7 @@ import ()type SearchRepo interface {- SearchContents(ctx context.Context, words []string, tagID, userID string, votes int, page, size int) (resp []schema.SearchResp, total int64, err error)- SearchQuestions(ctx context.Context, words []string, limitNoAccepted bool, answers, page, size int) (resp []schema.SearchResp, total int64, err error)- SearchAnswers(ctx context.Context, words []string, limitAccepted bool, questionID string, page, size int) (resp []schema.SearchResp, total int64, err error)+ SearchContents(ctx context.Context, words []string, tagID, userID string, votes, page, size int, order string) (resp []schema.SearchResp, total int64, err error)+ SearchQuestions(ctx context.Context, words []string, limitNoAccepted bool, answers, page, size int, order string) (resp []schema.SearchResp, total int64, err error)+ SearchAnswers(ctx context.Context, words []string, limitAccepted bool, questionID string, page, size int, order string) (resp []schema.SearchResp, total int64, err error)}