13

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?

Joey
  • 7,537
  • 12
  • 52
  • 104

3 Answers3

6

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.

Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
  • is there a working sample for this model? Like I need to get results of age>26 and height>113 . How would I map/query it? – nanospeck Nov 20 '13 at 17:54
  • As well as age you could maybe store 'decade' for each user, like 0, 10, 20, 30, 40, etc. Then do a query where height > 113 and age in [20, 30, 40, (and so on up to say 100)]. Then once you get the results, manually filter out the ones which are less than 26. – Saxon Druce Nov 20 '13 at 23:42
3

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

Drew Sears
  • 12,812
  • 1
  • 32
  • 41
1

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.

NickZoic
  • 7,575
  • 3
  • 25
  • 18