如何有效地对应用引擎中的查询运行两个不等式过滤器 [英] how to effectively run two inequality filters on queries in app engine

查看:20
本文介绍了如何有效地对应用引擎中的查询运行两个不等式过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道应用引擎有不等式过滤器只允许在一个属性上使用"的限制,如下所述:http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Introducing_Indexes

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

但是有什么方法可以基本上运行两个过滤器,或者这根本不可能?例如,如果我有一个只有 X 和 Y 坐标的实体类型,并且我想要 X1 到 X2 和 Y1 到 Y2 特定范围内的所有实体,是否有某种方法可以查询从 X1 到 X1 的所有实体?X2 按其 Y 值排序,然后轻松获取我想要的 Y 值范围之间的相关值?

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?

推荐答案

如果它适合您的数据,您可以将 X 和 Y 离散到 bin 中,生成两个值的散列,并将其存储在模型中.然后,您可以对与您要搜索的区域重叠的哈希进行精确查找.然后,手动过滤掉您所在地区以外的结果.

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.

这基本上就是 geomodel 为纬度/经度所做的.

This is essentially what geomodel is doing for latitude/longitude.

这篇关于如何有效地对应用引擎中的查询运行两个不等式过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆