JDOQL (Appengine) - 使用列表作为参数查询所有/一个项目?
我正在尝试创建一个查询,以便给定列表(参数)的所有项目都包含在表的列(这也是一个列表)中。我还需要一个查询,以便给定列表(参数)中的至少一项包含在表的列中。例如:
JDO:
Table: User
| ID | Name | Interests <List of Strings> |
查询:
List <String> gifts; // Item to query with
如何查询兴趣与所有礼物匹配的所有用户?即所有礼物都应该是兴趣的子集。
如何查询兴趣与某些(至少一项)礼物相匹配的所有用户?即至少一件礼物是兴趣的子集。
如何查询所有兴趣都与礼物匹配的所有用户?即所有兴趣都应该是礼物的子集。
如何查询某些(至少一项)兴趣与礼物匹配的所有用户?即至少一种兴趣是礼物的子集。
这些查询可以吗?如果是这样那怎么办?我可以使用 .contains()
关键字来执行这些查询吗?如果是这样,那又如何呢?谁能分享一些例子吗?任何帮助将不胜感激。
谢谢。
I'm trying to create a query so that all items of a given list (parameter) are contained in a a table's column (which is also a list). I also need a query so that at least one item of a given list (parameter) are contained in a table's column. For example:
JDO:
Table: User
| ID | Name | Interests <List of Strings> |
Query:
List <String> gifts; // Item to query with
How can I query for all users whose interests match ALL gifts? i.e. ALL of gifts should be a subset of Interests.
How can I query for all users whose interests match SOME (at least one) gift? i.e. at least one gift is a subset of the interests.
How can I query for all users whose ALL interests match gifts? i.e. ALL of interests should be a subset of gifts.
How can I query for all users whose SOME (at least one) interests match gifts? i.e. at least one interest is a subset of the gifts.
Are these queries possible? If so then how? Can I use the .contains()
keyword to do these queries? If so, then how? Can anyone share some examples? Any help would be highly appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了了解此类查询如何工作(或不工作),了解数据存储如何索引实体非常重要。当您插入具有列表属性的实体时,数据存储会将每个列表条目分解为单独的索引行。例如,以下实体:
将在自动索引中产生以下索引条目:
如果您还定义了(名称,兴趣)的复合索引,则其中的条目将如下所示:
建立后,我们可以按顺序处理您的特定查询:
对于数字 1 和 3,您可以通过进行更粗略的过滤(例如,搜索一两个兴趣)并过滤内存中的结果以获取精确匹配来完成。
In order to understand how these sort of queries work (or don't), it's important to understand how the datastore indexes entities. When you insert an entity with a list property, the datastore breaks out each list entry into a separate index row. For example, the following entity:
Will result in the following index entries in the automatic indexes:
If you've also defined a composite index on (name, interests), the entries in that will look something like this:
With that established, we can address your specific querying queries, in order:
For numbers 1 and 3, you may be able to get by by doing a coarser filter - for instance, searching on one or two interests - and filtering the results in memory for exact matches.