Python 2.7은 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
QueryOptions 클래스는 애플리케이션의 요구사항에 따라 쿼리 결과를 후처리하는 옵션을 제공합니다. 이 클래스를 Query.options 인수의 options로 구성합니다.
Query은 google.appengine.api.search 모듈에 정의됩니다.
소개
QueryOptions 클래스는 특정 쿼리의 결과를 후처리하는 옵션을 제공합니다. 옵션에는 결과 정렬, 반환할 문서 필드 제어, 필드 스니펫 생성, 복잡한 점수 표현식에 따른 계산 및 정렬 기능이 포함됩니다.
검색결과 페이지에 임의로 액세스하려면 다음 오프셋을 사용할 수 있습니다.
fromgoogle.appengine.apiimportsearch...# get the first set of resultspage_size=10results=index.search(search.Query(query_string='some stuff',options=search.QueryOptions(limit=page_size))# calculate pagespages=results.number_found/page_size# user chooses page and hence an offset into resultsnext_page=ith*page_size# get the search results for that pageresults=index.search(search.Query(query_string='some stuff',options=search.QueryOptions(limit=page_size,offset=next_page))
예를 들어 다음 코드 프래그먼트는 subject 필드에서 first가 발생하고 어느 위치에서든 good이 발생하는 문서 검색을 요청하여 최대 20개의 문서를 반환하고, 결과의 다음 페이지에 대한 커서를 요청하고, 결과의 다음 세트에 대한 또 다른 커서를 반환하고, 제목 내림차순으로 정렬하고, 작성자, 제목, 요약 필드와 스니펫 처리된 필드 내용을 반환합니다.
SearchResults.number_found의 최소 정확도 요구 사항이며, 설정되면 최소한 해당 숫자까지는 정확합니다. 예를 들어 100으로 설정하면 number_found_accuracy <= 100인 모든 SearchResults 객체가 정확합니다.
cursor
다음 결과 세트를 가져올 위치를 설명하거나 SearchResults에서 다음 커서를 제공하는 커서입니다.
offset
offset은 검색결과에서 건너뛸 문서 수를 나타냅니다. 쿼리 커서 대신 사용할 수 있으며, 항상 결과에 임의로 액세스할 수 있습니다. offset은 cursor보다 인스턴스 시간 측면에서 더 비용이 많이 듭니다. cursor 또는 offset 중 하나를 사용할 수 있지만 둘 다 사용할 수는 없습니다. offset을 사용하면 ScoredDocument.cursor 또는 ScoredDocument.cursor에 cursor가 반환되지 않습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003e\u003ccode\u003eQueryOptions\u003c/code\u003e class allows for post-processing of search query results, including sorting, field selection, snippet generation, and complex scoring expressions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003elimit\u003c/code\u003e parameter in \u003ccode\u003eQueryOptions\u003c/code\u003e controls the maximum number of documents returned in the search results.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eoffset\u003c/code\u003e parameter enables random access to pages of search results by skipping a specified number of documents, offering an alternative to using query cursors.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify which document fields to return using the \u003ccode\u003ereturned_fields\u003c/code\u003e parameter and which fields to snippet using \u003ccode\u003esnippeted_fields\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003enumber_found_accuracy\u003c/code\u003e parameter can be used to specify the minimum accuracy for \u003ccode\u003eSearchResults.number_found\u003c/code\u003e, however it can introduce significant latency.\u003c/p\u003e\n"]]],[],null,["# The QueryOptions Class\n\nClass `QueryOptions` provides options for post-processing query results based on the needs of your application. You construct the class as the `options` in the [Query.options](/appengine/docs/legacy/standard/python/search/queryclass) argument.\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\n`Query` is defined in the `google.appengine.api.search` module.\n\nIntroduction\n------------\n\nClass `QueryOptions` provides options for post-processing the results for a specific query. Options include the ability to sort results, control which document fields to return, produce snippets of fields and compute and sort by complex scoring expressions.\n\nIf you wish to randomly access pages of search results, you can use an offset: \n\n```python\nfrom google.appengine.api import search\n...\n# get the first set of results\npage_size = 10\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(limit=page_size))\n\n# calculate pages\npages = results.number_found / page_size\n\n# user chooses page and hence an offset into results\nnext_page = ith * page_size\n\n# get the search results for that page\nresults = index.search(search.Query(query_string='some stuff',\n options=search.QueryOptions(limit=page_size, offset=next_page))\n```\n\nFor example, the following code fragment requests a search for documents where `first` occurs in the `subject` field and `good` occurs in any field, returning at most 20 documents, requesting the cursor for the next page of results, returning another cursor for the next set of results, sorting by subject in descending order, returning the author, subject, and summary fields as well as a snippeted field content: \n\n```python\n...\nresults = index.search(search.Query(\n query='subject:first good',\n options=search.QueryOptions(\n limit=20,\n cursor=search.Cursor(),\n sort_options=search.SortOptions(\n expressions=[\n search.SortExpression(expression='subject', default_value='')],\n limit=1000),\n returned_fields=['author', 'subject', 'summary'],\n snippeted_fields=['content'])))\n```\n\nConstructor\n-----------\n\nThe constructor for class `QueryOptions` is defined as follows:\n\n\nclass QueryOptions(limit=20, number_found_accuracy=None, cursor=None, offset=None, sort_options=None, returned_fields=None, ids_only=False, snippeted_fields=None, returned_expressions=None)\n\n: Specify options defining search query results..\n\n: Arguments\n\n limit\n\n : The limit on number of documents to return in results.\n\n number_found_accuracy\n\n : The minimum accuracy requirement for `SearchResults.number_found`. If set, remains accurate up to at least that number. For example, when set to 100, any `SearchResults` object with `number_found_accuracy` \\\u003c= 100 is accurate.\n\n | **Caution!** This option may add considerable latency/expense, especially when used with `returned_fields`.\n\n cursor\n\n : A Cursor describing where to get the next set of results,\n or to provide next cursors in SearchResults.\n\n offset\n\n : The offset represents the number of documents to skip in search results. This is an alternative to using a query cursor. It allows random access to the results. Offsets are more expensive (in terms of [instance hours](/appengine/docs/pricing)) than cursors. You can use either cursor or offset, but not both. Using an offset means that no cursor is returned in [`ScoredDocument.cursor`](/appengine/docs/legacy/standard/python/search/searchresultsclass) or `ScoredDocument.cursor`.\n\n sort_options\n\n : A [SortOptions](/appengine/docs/legacy/standard/python/search/sortoptionsclass) object specifying a multi-dimensional sort over search results.\n\n returned_fields\n\n : An iterable of names of fields to return in search\n results.\n\n ids_only\n\n : Only return document ids, do not return any fields.\n\n snippeted_fields\n\n : An iterable of names of fields to snippet and return\n in search result expressions.\n\n returned_expressions\n\n : An iterable of FieldExpression to evaluate and\n return in search results.\n\n Result value\n\n : A new instance of class `QueryOptions`.\n\n Exceptions\n\n TypeError\n\n : If an unknown iterator_options or sort_options is passed.\n\n ValueError\n\n : If `ids_only` and `returned_fields` are used together.\n\n \u003cbr /\u003e\n\nProperties\n----------\n\nAn instance of class `Query` has the following properties:\n\nlimit\n\n: Returns a limit on number of documents to return in results.\n\nnumber_found_accuracy\n\n: Returns minimum accuracy requirement for [SearchResults.number_found](/appengine/docs/legacy/standard/python/search/searchresultsclass).\n\ncursor\n\n: Returns the cursor for the query.\n\noffset\n\n: Returns the number of documents in search results to skip.\n\nsort_options\n\n: Returns a [SortOptions](/appengine/docs/legacy/standard/python/search/sortoptionsclass) object.\n\nreturned_fields\n\n: Returns an iterable of names of fields to return in search results.\n\nids_only\n\n: Returns only ` ` in search results.\n\nsnippeted_fields\n\n: Returns iterable of field names to snippet and return in results.\n\nreturned_expressions\n\n: Returns iterable of [FieldExpression](/appengine/docs/legacy/standard/python/search/fieldexpressionclass) to return in results."]]