Python 2.7 telah mencapai akhir dukungan
dan akan
dihentikan penggunaannya
pada 31 Januari 2026. Setelah penghentian penggunaan, Anda tidak akan dapat men-deploy aplikasi Python 2.7, meskipun organisasi Anda sebelumnya menggunakan kebijakan organisasi untuk mengaktifkan kembali deployment runtime lama. Aplikasi Python 2.7 yang ada akan terus berjalan dan menerima traffic setelah
tanggal penghentiannya. Sebaiknya Anda
bermigrasi ke versi Python terbaru yang didukung.
Class Cursor
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Class Cursor
menyediakan kursor di hasil penelusuran yang ditetapkan saat ini, sehingga Anda dapat mengambil kumpulan berikutnya berdasarkan kriteria yang ditentukan. Menggunakan cursor dapat meningkatkan performa dan konsistensi penomoran halaman saat indeks diupdate.
Berikut ini cara menggunakan kursor untuk mendapatkan halaman hasil berikutnya:
# 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)))
Jika Anda ingin melanjutkan penelusuran dari salah satu ScoredDocuments
di SearchResults
, tetapkan Cursor.per_result
ke 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)))
Kursor bisa di-cache sebagai string keamanan web yang dapat digunakan untuk merekonstruksi Cursor. Misalnya,
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)))
Konstruktor
Konstruktor untuk class Cursor
ditentukan sebagai berikut:
-
class Cursor(web_safe_string=None, per_result=False)
Buat instance class Cursor
.
Argumen
- per_result
Jika benar, akan menampilkan kursor per ScoredDocument di SearchResults. Jika salah, akan menampilkan satu kursor untuk semua SearchResults. Diabaikan jika menggunakan QueryOptions.offset
, karena pengguna bertanggung jawab untuk menghitung offset berikutnya (jika ada).
- web_safe_string
String kursor yang ditampilkan dari layanan penelusuran untuk ditafsirkan oleh layanan penelusuran guna mendapatkan kumpulan hasil berikutnya.
Nilai hasil
Instance baru dari class Cursor
.
Pengecualian
- ValueError
Jika web_safe_string
yang disediakan oleh API bukan format yang diperlukan.
Properti
Instance class Cursor
memiliki properti berikut:
- per_result
Menampilkan apakah akan menampilkan kursor untuk setiap ScoredDocument dalam hasil.
- web_safe_string
Menampilkan string kursor yang dihasilkan oleh layanan penelusuran.
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-11 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eCursor\u003c/code\u003e class enables retrieving subsequent sets of search results, enhancing pagination performance and consistency.\u003c/p\u003e\n"],["\u003cp\u003eCursors can be used to fetch the next set of results for an entire search query or for individual \u003ccode\u003eScoredDocuments\u003c/code\u003e within the results.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eper_result\u003c/code\u003e argument in the \u003ccode\u003eCursor\u003c/code\u003e constructor determines if a cursor is provided for each \u003ccode\u003eScoredDocument\u003c/code\u003e or the entire result set.\u003c/p\u003e\n"],["\u003cp\u003eCursors can be serialized into a web-safe string (\u003ccode\u003eweb_safe_string\u003c/code\u003e) for storage and later use to reconstruct the cursor for continued searching.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eCursor\u003c/code\u003e class is applicable for first generation runtimes, and migration options should be reviewed when upgrading to the second-generation runtimes.\u003c/p\u003e\n"]]],[],null,["# The Cursor Class\n\nThe `Cursor` class provides a cursor in the current set search results, allowing you to retrieve the next set based on criteria that you specify. Using cursors improves the performance and consistency of pagination as indexes are updated.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nThe following shows how to use the cursor to get the next page of results: \n\n```python\n# Get the first set of results, and return a cursor with that result set.\n# The first cursor tells the API to return cursors in the SearchResults object.\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(cursor=search.Cursor()))\n\n# Get the next set of results with a cursor.\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(cursor=results.cursor)))\n```\n\nIf you want to continue search from any one of the `ScoredDocuments` in `SearchResults`, set `Cursor.per_result` to `True`: \n\n```python\n# get the first set of results, the first cursor is used to specify\n# that cursors are to be returned in the SearchResults.\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(cursor=Cursor(per_result=True)))\n\n# this shows how to access the per_document cursors returned from a search\nper_document_cursor = None\nfor scored_document in results:\n per_document_cursor = scored_document.cursor\n\n# get the next set of results\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(cursor=per_document_cursor)))\n```\n\nThe cursor can be cached as a web safe string that can be used to reconstruct the Cursor. For example, \n\n```python\nnext_cursor = results.cursor\nnext_cursor_url_safe = next_cursor.web_safe_string\n\n// save next_cursor_url_safe\n...\n// extract next_cursor_url_safe\n\nresults = index.search(\n search.Query(query_string,\n cursor=search.Cursor(web_safe_string=next_cursor_url_safe)))\n```\n\nConstructor\n-----------\n\nThe constructor for class `Cursor` is defined as follows:\n\n\nclass Cursor(web_safe_string=None, per_result=False)\n\n: Construct an instance of class `Cursor`.\n\n Arguments\n\n per_result\n\n : When true, returns a cursor per ScoredDocument in SearchResults. When false, returns a single cursor for all of SearchResults. Ignored if using [QueryOptions.offset](/appengine/docs/legacy/standard/python/search/queryoptionsclass), as the user is responsible for calculating a next offset (if any).\n\n web_safe_string\n\n : The cursor string returned from the search service to be interpreted by the search service to get the next set of results.\n\n Result value\n\n : A new instance of class `Cursor`.\n\n Exceptions\n\n ValueError\n\n : If the `web_safe_string` provided by the API is not of required format.\n\n \u003cbr /\u003e\n\nProperties\n----------\n\nAn instance of class `Cursor` has the following properties:\n\nper_result\n\n: Returns whether to return a cursor for each ScoredDocument in results.\n\nweb_safe_string\n\n: Returns the cursor string generated by the search service."]]