how to effectively run two inequality filters on q

2019-01-11 04:52发布

I'm aware that app engine has 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?

3条回答
何必那么认真
2楼-- · 2019-01-11 04:55

According to Alfred Fuller's recent Google I/O talk, they're working on support for multiple inequality filters on numeric properties.

查看更多
做自己的国王
3楼-- · 2019-01-11 04:55

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.

查看更多
男人必须洒脱
4楼-- · 2019-01-11 05:10

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.

查看更多
登录 后发表回答