Options for post-processing results for a 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:
# get the first set of results
page_size = 10
results = index.search(Query(query_string='some stuff',
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(Query(query_string='some stuff',
QueryOptions(limit=page_size, offset=next_page))
def google.appengine.api.search.search.QueryOptions.__init__ |
( |
|
self, |
|
|
|
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 |
|
) |
| |
Initializer.
For example, the following code fragment requests a search for
documents where 'first' occurs in subject and 'good' occurs anywhere,
returning at most 20 documents, starting the search from 'cursor token',
returning another single cursor for the SearchResults, sorting by subject in
descending order, returning the author, subject, and summary fields as well
as a snippeted field content.
results = index.search(Query(
query='subject:first good',
options=QueryOptions(
limit=20,
cursor=Cursor(),
sort_options=SortOptions(
expressions=[
SortExpression(expression='subject')],
limit=1000),
returned_fields=['author', 'subject', 'summary'],
snippeted_fields=['content'])))
Args:
limit: The limit on number of documents to return in results.
number_found_accuracy: The minimum accuracy requirement for
SearchResults.number_found. If set, the number_found will be
accurate up to at least that number. For example, when set to 100,
any SearchResults with number_found <= 100 is accurate. This option
may add considerable latency/expense, especially when used with
returned_fields.
cursor: A Cursor describing where to get the next set of results,
or to provide next cursors in SearchResults.
offset: The offset is number of documents to skip in search results. This
is an alternative to using a query cursor, but allows random access into
the results. Using offsets rather than cursors are more expensive. You
can only use either cursor or offset, but not both. Using an offset
means that no cursor is returned in SearchResults.cursor, nor in each
ScoredDocument.cursor.
sort_options: A SortOptions specifying a multi-dimensional sort over
search results.
returned_fields: An iterable of names of fields to return in search
results.
ids_only: Only return document ids, do not return any fields.
snippeted_fields: An iterable of names of fields to snippet and return
in search result expressions.
returned_expressions: An iterable of FieldExpression to evaluate and
return in search results.
Raises:
TypeError: If an unknown iterator_options or sort_options is passed.
ValueError: If ids_only and returned_fields are used together.
ExpressionError: If one of the returned expression strings is not
parseable.