I’m testing the fulltext search python api of Google App Angine.
The api search engine works fine, but I could not manage to get ordered results, following the basic steps described at: https://developers.google.com/appengine/docs/python/search/sortexpressionclass
The search function is really simple, but sort_options does not look to make any difference
def FindDocuments(self, query_string, limit):
try:
sort_options=search.SortOptions(expressions=[search.SortExpression(expression='comment', default_value='',direction=search.SortExpression.ASCENDING)])
query_options = search.QueryOptions(limit=limit,sort_options=sort_options)
query_obj = search.Query(query_string=query_string, options=query_options)
return search.Index(name=_INDEX_NAME).search(query=query_obj)
except search.Error:
logging.exception('Search failed')
return None
Searching for the word ‘item’ the result set are always unsorted:
item 4
item 3
item 1
item 2
All document items are proper returned, but never sorted.
It only works if I code the function to sort the results object:
results = sorted(results, key=lambda k: k.order_id)
But It does not looks to be the proper way once the sort is already an argument of the query object.
I would thanking you all for any sort of clue.
Are you trying this on your local dev server? According to this ticket the direction functionality doesn’t work locally but should work as expected when deployed.