Cursor クラスは、検索結果の現在のセットにカーソルを提供します。これにより、指定した条件に基づいて次の結果セットを取得できます。カーソルを使用すると、インデックスの更新時にページ設定のパフォーマンスと一貫性が改善されます。
カーソルを使用して次の結果ページを取得する方法は次のとおりです。
# Get the first set of results, and return a cursor with that result set. # The first cursor tells the API to return cursors in the SearchResults object. results = index.search(search.Query(query_string='some stuff', options=search.QueryOptions(cursor=search.Cursor())) # Get the next set of results with a cursor. results = index.search(search.Query(query_string='some stuff', options=search.QueryOptions(cursor=results.cursor)))
SearchResults のいずれか 1 つの ScoredDocuments から検索を続ける場合は、Cursor.per_result を 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(search.Query(query_string='some stuff', options=search.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(search.Query(query_string='some stuff', options=search.QueryOptions(cursor=per_document_cursor)))
カーソルは、Cursor の再構築に利用できるウェブセーフな文字列としてキャッシュに保存できます。例を次に示します。
next_cursor = results.cursor next_cursor_url_safe = next_cursor.web_safe_string // save next_cursor_url_safe ... // extract next_cursor_url_safe results = index.search( search.Query(query_string, cursor=search.Cursor(web_safe_string=next_cursor_url_safe)))
コンストラクタ
Cursor クラスのコンストラクタは、次のように定義されます。
- 
      class Cursor(web_safe_string=None, per_result=False) 
- クラス - Cursorのインスタンスを作成します。- 引数 - per_result
- true の場合、SearchResults の ScoredDocument ごとにカーソルを返します。false の場合、すべての SearchResults に対して 1 つのカーソルを返します。 - QueryOptions.offsetを使用する場合には、ユーザーが次のオフセット(該当する場合)を計算するため、無視されます。
- web_safe_string
- 検索サービスから返されるカーソル文字列。検索サービスにより、次の結果セットを取得するものと解釈されます。 
 - 結果値 - Cursorクラスの新しいインスタンス。
 - 例外 - ValueError
- API によって提供される - web_safe_stringの形式が必須でない場合。
 
プロパティ
Cursor クラスのインスタンスには次のプロパティがあります。
- per_result
- 結果の ScoredDocument ごとにカーソルを返すかどうかを返します。 
- web_safe_string
- 検索サービスにより生成されるカーソル文字列を返します。