John Wheeler
John Wheeler

Reputation: 797

TransientError with Google App Engine Search

I'm trying to run a query and sorting by a date field.

q = self.request.get("q")
index = search.Index(name="transaction")

sort_options = search.SortOptions(
    expressions=[
        search.SortExpression(expression='timestamp_date', direction=search.SortExpression.DESCENDING)
    ],
    limit=1000)
options = search.QueryOptions(limit=30, cursor=search.Cursor(), sort_options=sort_options)

results = index.search(search.Query(query_string=q, options=options))

On the development server, the code works but the results are not correctly sorted. On the production server it doesn't work at all; It gives the following error:

Search failed
Traceback (most recent call last):
  File "/base/data/home/apps/s~xxx/pre-24.359846149527858049/main.py", line 78, in get
    results = index.search(search.Query(query_string=q, options=options))
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2609, in search
    _CheckStatus(response.status())
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 414, in _CheckStatus
    raise _ERROR_MAP[status.code()](status.error_detail())
TransientError

I'm wondering how to make it work on the production server and how to sort correctly on the development server. I know its experimental technology, but I wanted to check to see if this was something I was overlooking

Upvotes: 1

Views: 401

Answers (1)

Ged
Ged

Reputation: 66

You need to provide a default value for all SortExpressions. This will be made clear in a forthcoming release. Also there is no explicit support for default Date values yet, so you need to put a default numeric value representing the number of days since 1970-01-01. In the code below, I am using the date 1970-01-01 as the default by specifying a value of 0.

sort_options = search.SortOptions(
    expressions=[
        search.SortExpression(expression='timestamp_date', default_value=0)
    ])

Also note that you do not need to specify direction=search.SortExpression.DESCENDING as that is the default for direction. You do not need to specify the default value of 1000 for the limit either.

Upvotes: 3

Related Questions