对具有给定属性的所有实体(Java)的AppEngine数据存储查询 [英] AppEngine datastore query for all entities that have a given property (Java)

查看:92
本文介绍了对具有给定属性的所有实体(Java)的AppEngine数据存储查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一种优雅的方式来查询AppEngine数据存储中具有特定属性的所有实体。由于缺乏属性的实体不包含在索引中,因此基本上我想要做的是检索给定属性的索引。我确信可以这样做:

I am trying to figure out an elegant way to query all of the entities in an AppEngine datastore that have a certain property. Since entities that lack a property aren't included in an index, basically what I want to do is to retrieve the index for a given property. I'm sure it's possible to do something like:

Filter bigger = new FilterPredicate(PROPERTY,
                  FilterOperator.GREATER_THAN_OR_EQUAL,
                  0);

Filter smaller = new FilterPredicate(PROPERTY,
                  FilterOperator.LESS_THAN_OR_EQUAL,
                  0);

Filter present = CompositeFilterOperator.or(bigger, smaller);

Query q = new Query(KIND).setFilter(present);

但它看起来不是非常优雅(或高效)的解决方案。有人有更好的主意吗?

but it doesn't look like a very elegant (or efficient) solution. Does anyone have a better idea?

推荐答案

我感兴趣的属性实际上是一个可能有很多值的列表,所以我决定让它保持未索引,并添加一个单独的布尔属性HAS_LIST。这允许我以稍微大一点的实体为代价对结果进行单个查询。仍然不是一个非常优雅的解决方案,但可能更有效一些。

The property I am interested in is actually a list which may have lots of values, so I decided to leave it unindexed, and add a separate boolean property HAS_LIST. That allows me to do a single query for results at the cost of a slightly bigger entity. Still not a very elegant solution, but perhaps a little more efficient.

这篇关于对具有给定属性的所有实体(Java)的AppEngine数据存储查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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