fix: search page

This commit is contained in:
kumfo 2022-10-12 16:09:20 +08:00 committed by mingcheng
parent c9016db8f8
commit dc5f6cc073
2 changed files with 7 additions and 3 deletions

View File

@ -105,7 +105,7 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,
return 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")) tr, err := sr.data.DB.Query(builder.MySQL().Select("count(*) total").From(b, "c"))
if len(tr) != 0 { if len(tr) != 0 {
@ -153,7 +153,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limit
} else if answers > 0 { } else if answers > 0 {
b.And(builder.Gte{"answer_count": answers}) 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")) 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}) 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")) tr, err := sr.data.DB.Query(builder.MySQL().Select("count(*) total").From(b, "c"))
total = converter.StringToInt64(string(tr[0]["total"])) total = converter.StringToInt64(string(tr[0]["total"]))

View File

@ -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) { func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (resp []schema.SearchResp, total int64, extra interface{}, err error) {
extra = nil extra = nil
if dto.Page < 1 {
dto.Page = 1
}
switch { switch {
case ss.tagSearch.Parse(dto): case ss.tagSearch.Parse(dto):
resp, total, err = ss.tagSearch.Search(ctx) resp, total, err = ss.tagSearch.Search(ctx)