【发布时间】:2016-05-31 05:51:44
【问题描述】:
目前我正在尝试查询位置实体,由两个范围过滤器过滤,这些过滤器将纬度和经度限制为当前视图。
查询应该以随机分布返回有限数量的实体。按原样查询会返回按纬度排序的集合。
Location Entity: Latitude, Longitude, ...
到目前为止,我的方法如下:我引入了一个 double 类型的 randomKey 属性,其范围为 [0...1]。我将它与每个 Location 实体一起存储在 Datastore 中,并尝试按该属性进行排序:
Location Entity: Latitude, Longitude, ..., randomKey
但是在执行了这个查询之后:
Query query = new Query("Location");
query.addSort("randomKey", Query.SortDirection.ASCENDING);
query.setFilter(latitudeRangeFilter);
query.setFilter(longitudeRangeFilter);
我得到一个 IllegalArgumentException:
java.lang.IllegalArgumentException: The first sort property must be the same as the property to which the inequality filter is applied. In your query the first sort property is randkey but the inequality filter is on longitude
有人可以给我一个关于如何进行的建议吗?我的方法是正确的还是有更好的方法?
提前致谢!
【问题讨论】:
标签: google-app-engine google-cloud-datastore