客观化查询字段不为空的所有记录的有效方法 [英] Efficient way to query all records where a field is not null in objectify

查看:97
本文介绍了客观化查询字段不为空的所有记录的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有效地查询索引字段以检索索引字段不为空(存在于索引中)的所有记录。要查询的字段包含 Ref< T> 到另一个实体,以防相关。



什么我能做的就是一个不等式搜索,比如 .filter / .filterKey(fieldname> =,a),其中a是我想要的最小的ASCII抓住。



但是这是否有效?或者我可以以某种方式进行平等搜索,它会返回索引中存在的所有记录?



-



这就是我的数据的样子:我想过滤overlay列中有关键字的所有记录,并省略那些未设置字段的记录。如果可能的话,我想使用平等过滤器,所以我不需要组合索引(因为我在同一时间在其他字段上进行过滤)。

img src =https://i.stack.imgur.com/lTnEE.pngalt =资料快照>



-



我可以用它来测试!= null

  .filter(user>,\\\�); 

,并且测试 == null

  .filter(user<,\\\�); 

我想这不是它应该完成的方式。有没有办法解决这个问题,使用相等而不是不平等?

解决方案

如果您想要查询具有null值为一个索引字段:

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

然而,这与平等过滤器不同。在封面之下,GAE将!=视为一对过滤器(>和<),这带来了不平等过滤器的限制。



如果您需要一个等式过滤not null,在您的实体中创建一个合成索引字段,该字段使用@OnSave方法填充。您可以对'真'值使用部分索引来限制索引这些额外数据的成本(即 @Index(IfTrue.class)


I want to query an indexed field efficiently to retrieve all records where the indexed field is not null (present in the index). The field to be queried contains a Ref<T> to another entity, in case this is relevant.

What I could do is an inequality search, like .filter/.filterKey("fieldname >=", "a"), where a is the smallest ASCII that I want to grab.

But is this efficient? Or can I do an equality search somehow, which returns all records that are present in the index?

--

This is how my data looks like: I want to filter all records where the "overlay" column has a key, and omit those where the field is not set. I would like to use an equality filter if possible, so I don't need a composite index (as I am filtering on other fields at the same time).

--

I can use this to test for != null

.filter("user >", "\uFFFD");

and this to test for == null

.filter("user <", "\uFFFD");

I guess that's not the way it should be done. Is there a way to solve this problem using equality instead of inequality?

解决方案

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))

这篇关于客观化查询字段不为空的所有记录的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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