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.
Asked
Active
Viewed 531 times
4
-
4The docs on that struct say: "Size/From describe how much and which part of the result set to return". Does that not work? There's also `NewSearchRequestOptions` to fill those fields in for you. – JimB Sep 14 '17 at 20:13
1 Answers
2
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.

Mark Ransom
- 473
- 1
- 4
- 15