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.
- Introduction
- Constructor
- Properties:
Introduction
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', search.QueryOptions(limit=page_size)) # calculate pages pages = results.found_count / 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', 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.