Efficient way to query all records where a field is not null in objectify

时光总嘲笑我的痴心妄想 提交于 2019-12-05 16:23:09

If you want to query for entities which have a null value for an indexed field:

ofy().load().type(Thing.class).filter("fieldname !=", null)

However, this is not the same thing as an equality filter. Under the covers, GAE treats != as a pair of filters (> and <) and this brings with it the limitations of inequality filters.

If you need an equality filter on "not null", create a synthetic indexed field in your entity which is populated using an @OnSave method. You can use a partial index on the 'true' value to limit the cost of indexing this extra data (ie, @Index(IfTrue.class))

If your property is String, a more efficient way than "!= null" is to use:

ofy().load().type(Thing.class).filter("fieldname >=", "");

Similarly, you can use > 0 if your property is a positive number, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!