xkm xkm - 17 days ago 6
Java Question

Ordering Query results by Date (String) for GAE

I have thousands of Entities stored in the GAE datastore where a field "create" is saved as a date

String
(standard format).

My question would be, is it still possible to do a
Query
like this:

Query q = new Query("Post")
.addSort("created", SortDirection.DESCENDING);


Where "
created
" is actually a date String, stored like this:
2014-12-11T14:31:43 -08:00"

and actually get a descending order. I've tried it but the result set is just as random and not even in order by date.

Is there a way to tweak a GAE
Query
to achieve this with this data?

Answer

Even if GAE has indexed date as string so '2014-12-11T14:31:43 -08:00' comes after '2014-12-04T14:31:43 -08:00' (just for example) which means natural sorting order should follow.

Have you indexed 'created' field? If not, GAE is gonna ignore the sort order you gave in query.

Comments