google 应用引擎 python 中基于地理空间和位置的搜索

geoSpatial & Location based search in google appengine python

我想在airbnb上实现类似地图拖拽搜索的功能(https://www.airbnb.com/s/Paris--France?source=ds&page=1&s_tag=PNoY_mlz&allow_override%5B%5D=)

我在数据存储中保存这样的数据

 user.lat = float(lat)
     user.lon = float(lon)
     user.geoLocation = ndb.GeoPt(float(lat),float(lon))

每当我拖放地图或放大或缩小时,我都会在控制器中获得以下参数

    def get(self):
    """
    This is an ajax function. It gets the place name, north_east, and south_west
    coordinates. Then it fetch the results matching the search criteria and
    create a result list. After that it returns the result in json format.
    :return: result
    """
    self.response.headers['Content-type'] = 'application/json'
    results = []
    north_east_latitude = float(self.request.get('nelat'))
    north_east_longitude = float(self.request.get('nelon'))
    south_west_latitude = float(self.request.get('swlat'))
    south_west_longitude = float(self.request.get('swlon'))
    points = Points.query(Points.lat<north_east_latitude,Points.lat>south_west_latitude)
    for row in points:
        if  row.lon > north_east_longitude and row.lon < south_west_longitude:
            listingdic = {'name': row.name, 'desc': row.description, 'contact': row.contact, 'lat': row.lat, 'lon': row.lon}
            results.append(listingdic)
    self.write(json.dumps({'listings':results}))

我的模型class如下

class Points(ndb.Model):
    name = ndb.StringProperty(required=True)
    description = ndb.StringProperty(required=True)
    contact = ndb.StringProperty(required=True)
    lat = ndb.FloatProperty(required=True)
    lon = ndb.FloatProperty(required=True)
    geoLocation = ndb.GeoPtProperty()

我想改进查询。

提前致谢。

不,您无法通过检查查询中的所有 4 个条件来改进解决方案,因为 ndb 查询不支持多个属性的不等式过滤器。来自 NDB Queries(强调我的):

Limitations: The Datastore enforces some restrictions on queries. Violating these will cause it to raise exceptions. For example, combining too many filters, using inequalities for multiple properties, or combining an inequality with a sort order on a different property are all currently disallowed. Also filters referencing multiple properties sometimes require secondary indexes to be configured.

Note: As mentioned earlier, the Datastore rejects queries using inequality filtering on more than one property.