按GAE的日期(字符串)排序查询结果 [英] Ordering Query results by Date (String) for GAE

查看:98
本文介绍了按GAE的日期(字符串)排序查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GAE数据存储中存储了数千个实体,其中字段create被保存为日期 String (标准格式)。



我的问题是,是否仍然可以像这样做 Query

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

其中创建实际上是一个日期字符串,像这样存储: 2014-12-11T14:31:43 -08:00
并且实际得到降序。结果集是随机的,甚至不按日期排序。



有没有办法调整GAE Query 用这个数据来实现这个目的?

解决方案

即使GAE将索引日期设置为字符串,因此'2014-12- 11:T14:31:43 -08:00'在'2014-12- 04 T14:31:43 -08:00'后面(例如),这意味着自然排序如果没有,GAE会忽略你在查询中给出的排序顺序。

$ b

你有没有索引'created'字段?

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?

解决方案

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.

这篇关于按GAE的日期(字符串)排序查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆