I'm aware that app engine ha开发者_开发技巧s the restriction of "Inequality Filters Are Allowed On One Property Only" as described here: http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Introducing_Indexes
However is there some way to essentially run two filters, or is this simply not possible? For instance, if I had an entity kind that simply had an X and Y coordinate, and I wanted all entities that are within a certain range of X1 to X2 and Y1 to Y2, is there some way to query for all entities from X1 to X2 sorted by their Y values and then easily grab the relevant ones between my desired range for the Y values?
If so, does someone have some example code to demonstrate?
If it suits your data, you can discretize your X and Y into bins, generate a hash of the two values, and store that on the model. Then you can do exact lookups for the hash(es) which overlap the region you want to search within. Then, manually filter out the results which are outside your region.
This is essentially what geomodel is doing for latitude/longitude.
According to Alfred Fuller's recent Google I/O talk, they're working on support for multiple inequality filters on numeric properties.
Depending on what you're trying to do, you might find this MultiInequalityMixin interesting. It does pretty much what you describe, passing the first inequality through to Google's database and doing subsequent inequalities as filters. Disclaimer: it's a pretty sketchy implementation of an idea I had over a year ago and haven't really every finished off ...
If you need efficient indexing on two axes, then as Saxon Druce says, some kind of geohash etc algorithm is what's called for.
精彩评论