Christian Siegert
Christian Siegert

Reputation: 1595

Google App Engine Search for Go: How to paginate?

If I query Google App Engine Search for Go, e.g. for the first 10 results, how do I do a follow-up query that fetches the next 10 results? There are no cursors I’m aware of.

Upvotes: 4

Views: 534

Answers (1)

icza
icza

Reputation: 417592

EDIT: Good News! Since writing this answer, Cursors for the Search API has been completed and published, and so it's generally available.

Check out the Cursor type. A Cursor value may be specified in the SearchOptions. So when you call Index.Search(), you may pass a SearchOptions with a Cursor you obtained previously from Iterator.Cursor().

Original answer follows below.


You are out of luck.

In general Cursors are supported for the Search API (for example see Java Using cursors) and it is also implemented in Go, but the cursor API for searches is incomplete and not exported.

For evidence see the source of search/search.go: the Iterator type (returned by both Index.List() and Index.Search() methods) has an unexported searchCursor field (currently line #602) which is exactly what we think it is, and it is used internally, it is just not exported.

If you check the source of the SearchOptions struct in the same source file (search/search.go) (this is what you can pass to the Index.Search() method when initiating/performing searches):

// Currently starts at line #464:
type SearchOptions struct {
    ...
    // TODO: cursor, offset, maybe others.
}

So there is plan to add support for Search cursors, offsets and others, it is just not yet implemented and exported. Hopefully will get added in a future release.

Upvotes: 6

Related Questions