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 us开发者_如何学Goed), 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
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.
精彩评论