Stay organized with collections Save and categorize content based on your preferences.
Class 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 argument.
Query
is defined in the google.appengine.api.search
module.
Class 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.
If you wish to randomly access pages of search results, you can use an offset:
from google.appengine.api import search ... # get the first set of results page_size = 10 results = index.search(search.Query(query_string='some stuff', options=search.QueryOptions(limit=page_size)) # calculate pages pages = results.number_found / page_size # user chooses page and hence an offset into results next_page = ith * page_size # get the search results for that page results = index.search(search.Query(query_string='some stuff', options=search.QueryOptions(limit=page_size, offset=next_page))
For 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:
... results = index.search(search.Query( query='subject:first good', options=search.QueryOptions( limit=20, cursor=search.Cursor(), sort_options=search.SortOptions( expressions=[ search.SortExpression(expression='subject', default_value='')], limit=1000), returned_fields=['author', 'subject', 'summary'], snippeted_fields=['content'])))Constructor
The constructor for class QueryOptions
is defined as follows:
class 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)
Specify options defining search query results..
Arguments
The limit on number of documents to return in results.
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
<= 100 is accurate.
returned_fields
.
A Cursor describing where to get the next set of results, or to provide next cursors in SearchResults.
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) than cursors. You can use either cursor or offset, but not both. Using an offset means that no cursor is returned in ScoredDocument.cursor
or ScoredDocument.cursor
.
A SortOptions
object specifying a multi-dimensional sort over search results.
An iterable of names of fields to return in search results.
Only return document ids, do not return any fields.
An iterable of names of fields to snippet and return in search result expressions.
An iterable of FieldExpression to evaluate and return in search results.
Result value
A new instance of class QueryOptions
.
Exceptions
If an unknown iterator_options or sort_options is passed.
If ids_only
and returned_fields
are used together.
An instance of class Query
has the following properties:
Returns a limit on number of documents to return in results.
Returns minimum accuracy requirement for SearchResults.number_found.
Returns the cursor for the query.
Returns the number of documents in search results to skip.
Returns a SortOptions object.
Returns an iterable of names of fields to return in search results.
Returns only
in search results.
Returns iterable of field names to snippet and return in results.
Returns iterable of FieldExpression to return in results.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["`QueryOptions` class allows for post-processing of search query results, including sorting, field selection, snippet generation, and complex scoring expressions."],["The `limit` parameter in `QueryOptions` controls the maximum number of documents returned in the search results."],["The `offset` parameter enables random access to pages of search results by skipping a specified number of documents, offering an alternative to using query cursors."],["You can specify which document fields to return using the `returned_fields` parameter and which fields to snippet using `snippeted_fields`."],["The `number_found_accuracy` parameter can be used to specify the minimum accuracy for `SearchResults.number_found`, however it can introduce significant latency."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4