blevesearch how to paginate results?

602 views Asked by At

I'm trying to integrate blevesearch in my app. How am I supposed to implement pagination? I can't find any param to indicate the page number, per-page limit or cursor in the docs.

1

There are 1 answers

0
Mark Ransom On

I ran into this issue while trying to add pagination to the gozim project, and I used JimB's comment to find a solution. I updated this:

queryString := r.FormValue("search_data")
query := bleve.NewQueryStringQuery(queryString)
search := bleve.NewSearchRequest(query)

To this:

queryString := r.FormValue("search_data")
pageString := r.FormValue("page")
pageNumber, _ := strconv.Atoi(pageString)
itemCount := 20
from := itemCount * pageNumber
query := bleve.NewQueryStringQuery(queryString)
search := bleve.NewSearchRequestOptions(query, itemCount, from, false)

And it appears to be working correctly.