View source on GitHub |
Specifies how to get the next page of results in a search.
Inherits From: expected_type
google.appengine.api.search.Cursor(
web_safe_string=None, per_result=False
)
A cursor returned in a previous set of search results to use as a starting point to retrieve the next set of results. This can get you better performance, and also improves the consistency of pagination through index updates.
The following shows how to use the cursor to get the next page of results:
get the first set of results; the first cursor is used to specify
that cursors are to be returned in the SearchResults.
results = index.search(Query(query_string='some stuff', QueryOptions(cursor=Cursor()))
get the next set of results
results = index.search(Query(query_string='some stuff', QueryOptions(cursor=results.cursor)))
If you want to continue search from any one of the ScoredDocuments in SearchResults, then you can set Cursor.per_result to True.
get the first set of results; the first cursor is used to specify
that cursors are to be returned in the SearchResults.
results = index.search(Query(query_string='some stuff', QueryOptions(cursor=Cursor(per_result=True)))
this shows how to access the per_document cursors returned from a search
per_document_cursor = None for scored_document in results: per_document_cursor = scored_document.cursor
get the next set of results
results = index.search(Query(query_string='some stuff', QueryOptions(cursor=per_document_cursor)))
Args | |
---|---|
web_safe_string
|
The cursor string returned from the search service to be interpreted by the search service to get the next set of results. |
per_result
|
A bool when true will return a cursor per ScoredDocument in SearchResults, otherwise will return a single cursor for the whole SearchResults. If using offset this is ignored, as the user is responsible for calculating a next offset if any. |
Raises | |
---|---|
ValueError
|
if the web_safe_string is not of required format. |
Attributes | |
---|---|
per_result
|
Returns whether to return a cursor for each ScoredDocument in results. |
web_safe_string
|
Returns the cursor string generated by the search service. |