GAE 中没有额外索引的查询
在 Google App Engine 应用程序(GAE/Java)中,我有一个这样的类:
public class Person{
private int born;
private String sex;
private List<String> likes;
//some other fields
...
}
我需要应用程序的用户可以在不同的字段上进行搜索。例如,用户可能要求搜索:
- 所有 1975 年之后出生且喜欢土豆和鱼的人
- 所有 1980 年之前出生且喜欢胡萝卜的女性
我的意思是,查询可能具有可变数量的过滤器。 查询不需要额外的索引非常重要,因此我阅读了文档,它说仅使用相等性的查询不需要额外的索引。
所以我想到使用 IN 运算符(因为它被转换为等于运算符),如下所示:
select from Person where
likes IN ("potatoes", "fish") AND
born IN (1975,1976....2011)
select from Person where
sex = 'female' AND
likes = "carrots" AND
born IN (1900,1901....1980)
问题在于,正如文档中所述:
IN 运算符还执行多个查询,一个查询针对所提供的列表值中的每一项,其中所有其他过滤器都相同,并且 IN 过滤器被替换为等于过滤器。结果将按列表中项目的顺序合并。如果某个查询有多个 IN 过滤器,则该查询将作为多个查询执行,每个查询对应 IN 过滤器中的值的每个组合。
包含 NOT_EQUAL 或 IN 运算符的单个查询仅限于 30 个子查询。
用户不会使用许多字段,通常在同一查询中最多使用 3 个字段(尽管可以使用许多字段) ),但我需要搜索任何年龄段的用户。所以这种方法最终会受到 30 个子查询的限制。
我怎样才能设计一个解决方案来解决这个问题?
谢谢
In a Google App Engine Application (GAE/Java) I have a class like this one:
public class Person{
private int born;
private String sex;
private List<String> likes;
//some other fields
...
}
I need that the user of the application can search on different fields. For example the user may ask for searching:
- All the people who were born after 1975 and like potatoes and fish
- All the women who were born before 1980 and like carrots
I mean, the queries may have a variable number of filters. It is very important that the query doesn't need an extra index, so I've read the documentation and it says that queries using only equality don't need an extra index.
So I have thought of using IN operator (because it is coverted to equals operator) like this:
select from Person where
likes IN ("potatoes", "fish") AND
born IN (1975,1976....2011)
select from Person where
sex = 'female' AND
likes = "carrots" AND
born IN (1900,1901....1980)
The problem is that as it is stated in the documentation:
The IN operator also performs multiple queries, one for each item in the provided list value where all other filters are the same and the IN filter is replaced with an equal-to filter. The results are merged, in the order of the items in the list. If a query has more than one IN filter, the query is performed as multiple queries, one for each combination of values in the IN filters.
A single query containing NOT_EQUAL or IN operators is limited to 30 sub-queries.
The user won't user many fields, typically at most 3 in the same query (though there are many fields that can be used), but I need to search for users in any range of age. So this approach will end in the limitation of the 30 sub-queries.
How can I design a solution which solves this problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是您想听到的,但不幸的是,应用程序引擎数据存储目前对于您的应用程序来说并不是一个好的选择。它不能很好地支持数据挖掘或重要的用户生成的查询,而您正在尝试在此处执行此操作。
由于全文搜索(在路线图上),这种情况将来会发生变化、托管 SQL 数据库(App Engine for Business)和查询引擎改进由 Alfred Fuller 描述。但是,如果您等不及这些,则需要寻找其他地方。
this isn't what you want to hear, but unfortunately, the app engine datastore currently isn't a good choice for your application. it doesn't support data mining or nontrivial user-generated queries well, which you're trying to do here.
that will change in the future, due to full text search (on the roadmap), hosted SQL databases (in App Engine for Business) and query engine improvements described by Alfred Fuller. if you can't wait for those, though, you'll need to look elsewhere.