Fixed pager
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user