简体   繁体   English

对象化中的复杂查询

[英]complex queries in objectify

Consider a more complex entity structure like 考虑一个更复杂的实体结构,例如

class Entity {
    Float valueA;
    Float valueB;
    List<Property> properties;
}

class Property {
    Long id;
    Float value;
}

I'm now trying to figure out an index structure to do queries like (Pseudo sql): 我现在正试图找出一个索引结构来进行类似(伪sql)的查询:

select entity where valueA >= x and valueB < y and properties contains
((id = a, value >= b) and (id = c, value = d))

The problems I'm facing are: 我面临的问题是:

  • I can't put multible inequality filters in one query. 我不能在一个查询中放置多重不等式过滤器。
  • How would I add constraints for the list property objects 如何为列表属性对象添加约束

So far I have one idea that came accross my mind: 到目前为止,我的想法浮现在脑海:

I could make use of the relation index pattern for all properties. 我可以为所有属性使用关系索引模式。 Eg. 例如。 create the following entities: 创建以下实体:

class ValueA/ValueB {
   @Parent
   Key<Entity> parent;
   @Id
   Long id = 1L;
   @Index
   Float minValue;
}

and change the Property class like 并像更改Property类

class Property {
    @Parent
    Key<Entity> parent;
    @Id
    Long id;
    @Index
    Float value;
}

Then I could do a query for every related index class and keep the parent keys of those entities that mach all criteria. 然后,我可以查询每个相关的索引类,并保留满足所有条件的那些实体的父键。

This would be hard to do efficiently and could easily get very expensive. 这将很难高效地完成,并且很容易变得非常昂贵。

Are there any other solutions I could try out? 还有其他可以尝试的解决方案吗?

Thanks in advance! 提前致谢!

I would store a denormalized copy of my Entity in the Search Api, which allows for much more flexible querying. 我将实体的非规范化副本存储在Search Api中,这使查询更加灵活。

Make sure that your result from the Search Api contains the Id of the entities. 确保您从“搜索Api”获得的结果包含实体的ID。

Finally, do a keys() query with Objectify to get to the actual entities of your result. 最后,使用Objectify进行keys()查询以获取结果的实际实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM