diff --git a/internal/repo/search_repo.go b/internal/repo/search_repo.go index 52bf43ac..f6277c19 100644 --- a/internal/repo/search_repo.go +++ b/internal/repo/search_repo.go @@ -105,7 +105,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID, return } - res, err := sr.data.DB.Query(builder.MySQL().Select("*").From(b, "t").OrderBy(sr.parseOrder(ctx, order)).Limit(size, page)) + res, err := sr.data.DB.Query(builder.MySQL().Select("*").From(b, "t").OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1)) tr, err := sr.data.DB.Query(builder.MySQL().Select("count(*) total").From(b, "c")) if len(tr) != 0 { @@ -153,7 +153,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limit } else if answers > 0 { b.And(builder.Gte{"answer_count": answers}) } - res, err := sr.data.DB.Query(b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page)) + res, err := sr.data.DB.Query(b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1)) tr, err := sr.data.DB.Query(builder.MySQL().Select("count(*) total").From(b, "c")) @@ -203,7 +203,7 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAc b.Where(builder.Eq{"question_id": questionID}) } - res, err := sr.data.DB.Query(b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page)) + res, err := sr.data.DB.Query(b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1)) tr, err := sr.data.DB.Query(builder.MySQL().Select("count(*) total").From(b, "c")) total = converter.StringToInt64(string(tr[0]["total"])) diff --git a/internal/service/search_service.go b/internal/service/search_service.go index b292a99c..817c2318 100644 --- a/internal/service/search_service.go +++ b/internal/service/search_service.go @@ -57,6 +57,10 @@ func NewSearchService( func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (resp []schema.SearchResp, total int64, extra interface{}, err error) { extra = nil + if dto.Page < 1 { + dto.Page = 1 + } + switch { case ss.tagSearch.Parse(dto): resp, total, err = ss.tagSearch.Search(ctx)