Fixed pager

This commit is contained in:
James Mills
2021-02-03 01:56:56 +10:00
parent 382fd677c3
commit 6dc7510e8f
6 changed files with 37 additions and 20 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/james4k/fmatter"
"github.com/julienschmidt/httprouter"
log "github.com/sirupsen/logrus"
"github.com/vcraescu/go-paginator"
)
const (
@@ -196,7 +197,9 @@ func (s *Server) SearchHandler() httprouter.Handle {
return
}
searchResults, err := s.indexer.Search(q)
p := SafeParseInt(r.FormValue("p"), 1)
searchResults, err := s.indexer.Search(q, p)
if err != nil {
log.WithError(err).Error("error performing search")
ctx.Error = true
@@ -220,10 +223,13 @@ func (s *Server) SearchHandler() httprouter.Handle {
results = append(results, result)
}
pager := paginator.New(IntAdapter{N: int(searchResults.Total)}, s.config.ResultsPerPage)
pager.SetPage(p)
ctx.Pager = &pager
ctx.SearchQuery = q
ctx.Results = results
ctx.Matches = searchResults.Total
ctx.Duration = searchResults.Took.Truncate(time.Nanosecond)
ctx.SearchTook = searchResults.Took.Truncate(time.Nanosecond)
s.render("search", w, ctx)
}