'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 document cursor for the results, 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_string=\'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\']),
facet_refinements=[ref_key1, ref_key2]))
In order to get a Cursor, you specify a Cursor in QueryOptions.cursor
and extract the Cursor for the next request from results.cursor to
continue from the last found document, as shown below:
results = index.search(
Query(query_string=\'subject:first good\',
options=QueryOptions(cursor=results.cursor)))
To enable faceted search in the result, you can use
enable_facet_discovery or return_facets, as shown below:
# discover top facets
results = index.search(
Query(query_string=\'movies\',
enable_facet_discovery=true))
# included specific facets with search result
results = index.search(
Query(query_string=\'movies\',
return_facets=[\'rating\', \'shipping_method\']))
# discover only 5 facets and two manual facets with customized value
facet_option = FacetOption(discovery_limit=5)
facet1 = FacetRequest(\'Rating\', ranges=[
FacetRange(start=1.0, end=2.0),
FacetRange(start=2.0, end=3.5),
FacetRange(start=3.5, end=4.0)]
results = index.search(
Query(query_string=\'movies\',
enable_facet_discovery=true,
facet_option=facet_option,
return_facets=[facet1, \'shipping_method\']))
Args:
query_string: The query to match against documents in the index. A query
is a boolean expression containing terms.  For example, the query
\'job tag:"very important" sent <= 2011-02-28\'
finds documents with the term job in any field, that contain the
phrase "very important" in a tag field, and a sent date up to and
including 28th February, 2011.  You can use combinations of
\'(cat OR feline) food NOT dog\'
to find documents which contain the term cat or feline as well as food,
but do not mention the term dog. A further example,
\'category:televisions brand:sony price >= 300 price < 400\'
will return documents which have televisions in a category field, a
sony brand and a price field which is 300 (inclusive) to 400
(exclusive).  See
https://developers.google.com/appengine/docs/python/search/overview#Expressions
for a list of expressions that can be used in queries.
options: A QueryOptions describing post-processing of search results.
enable_facet_discovery: discovery top relevent facets to this search query
and return them.
return_facets: An iterable of FacetRequest or basestring as facet name to
return specific facet with the result.
facet_options: A FacetOption describing processing of facets.
facet_refinements: An iterable of FacetRefinement objects or refinement
token strings used to filter out search results based on a facet value.
refinements for different facets will be conjunction and refinements for
the same facet will be disjunction.
Raises:
QueryError: If the query string is not parseable.'

@datastore_rpc._positional(3)
def __init__(self, query_string, options=None, enable_facet_discovery=False, return_facets=None, facet_options=None, facet_refinements=None):

    self._query_string = _ConvertToUnicode(query_string)
    _CheckQuery(self._query_string)
    self._options = options
    self._facet_options = facet_options
    self._enable_facet_discovery = enable_facet_discovery
    self._return_facets = _ConvertToListAndCheckType(return_facets, (basestring, FacetRequest), 'return_facet')
    for (index, facet) in enumerate(self._return_facets):
        if isinstance(facet, basestring):
            self._return_facets[index] = FacetRequest(self._return_facets[index])
    self._facet_refinements = _ConvertToListAndCheckType(facet_refinements, (basestring, FacetRefinement), 'facet_refinements')
    for (index, refinement) in enumerate(self._facet_refinements):
        if isinstance(refinement, basestring):
            self._facet_refinements[index] = FacetRefinement.FromTokenString(refinement)
