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

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

问题描述

我知道,应用引擎具有不允许在一个媒体资源上使用不公平筛选器的限制/queriesandindexes.html#Introducing_Indexesrel =noreferrer> http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Introducing_Indexes



但是有没有办法实质上运行两个过滤器,或者这是不可能的?例如,如果我有一个只具有X和Y坐标的实体类型,并且我想要在X1到X2和Y1到Y2的一定范围内的所有实体,是否有一些方法可以查询从X1到X2按它们的Y值排序,然后轻松获取我想要的Y值之间的相关值?如果是这样,有人有一些示例代码来演示吗?如果它适合你的数据,你可以离散你的X和Y到垃圾箱,生成这两个值的散列,并存储在模型上。然后,您可以对与要在其中搜索的区域重叠的哈希(es)进行精确查找。然后,手动过滤出您所在地区以外的结果。



这实质上就是 geomodel 正在为纬度/经度做准备。


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?

解决方案

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.

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

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