Java 在FieldExpression中,地点函数距离不起作用

Java 在FieldExpression中,地点函数距离不起作用,java,google-app-engine,search,Java,Google App Engine,Search,我正在使用谷歌应用程序引擎,并将地理点存储在可搜索的文档索引中。当我使用距离函数搜索位置时,例如“distance(myGeoPoint,geopoint(35.2,40.5))>100”,搜索返回预期的文档。在返回的结果中,我想找出每个myGeoPoint与传入的geopoint之间的距离,所以我在QueryOptions中添加了一个“距离”字段表达式,但看起来该字段表达式没有得到计算,search以HTML形式返回该字段,并带有空值。但为了确保正确构建FieldExpression,我尝试用

我正在使用谷歌应用程序引擎,并将地理点存储在可搜索的文档索引中。当我使用距离函数搜索位置时,例如“distance(myGeoPoint,geopoint(35.2,40.5))>100”,搜索返回预期的文档。在返回的结果中,我想找出每个myGeoPoint与传入的geopoint之间的距离,所以我在QueryOptions中添加了一个“距离”字段表达式,但看起来该字段表达式没有得到计算,search以HTML形式返回该字段,并带有空值。但为了确保正确构建FieldExpression,我尝试用其他表达式替换该表达式,例如(count(someOtherField)),它可以工作并返回正确的数据。看来距离函数的用法有问题。有人知道我在FieldExpression中使用距离函数有什么问题吗?应该能用的,对吗?FieldExpressions不支持或距离函数

或者,是否有其他方法获取兴趣点到所有匹配搜索查询的位置之间的距离

我的示例代码:

    // use search api
    IndexSpec indexSpec = IndexSpec.newBuilder().setName(
            "com.mycompany").build();
    Index index = SearchServiceFactory.getSearchService()
            .getIndex(indexSpec);
    QueryOptions options = QueryOptions.newBuilder()
            .setLimit(100)
            .setFieldsToReturn("myGeoPoint")
            .addExpressionToReturn(FieldExpression.newBuilder()
                    .setName("calculatedDistance")
                    .setExpression("distance(myGeoPoint, geopoint(37.738767, -122.424037))"))
            .build();
    Query query = Query.newBuilder().setOptions(options).build("distance(myGeoPoint, geopoint(37.738767, -122.424037)) < 10000");

    Results<ScoredDocument> results = null;
    try {
        results = index.search(query);
        for (ScoredDocument document : results) {
            List<Field> expressions = document.getExpressions();
            for (Field e : expressions) {
                System.out.println("expression=" + e);  
            }
        }
    } catch (SearchException e) {
        if (StatusCode.TRANSIENT_ERROR.equals(
                e.getOperationResult().getCode())) {
            results = index.search(query);                
        }
    }
//使用搜索api
IndexSpec IndexSpec=IndexSpec.newBuilder().setName(
“com.mycompany”).build();
Index=SearchServiceFactory.getSearchService()
.getIndex(indexSpec);
QueryOptions options=QueryOptions.newBuilder()
.setLimit(100)
.setFieldsToReturn(“myGeoPoint”)
.AddExpressionReturn(FieldExpression.newBuilder()
.setName(“计算距离”)
.setExpression(“距离(myGeoPoint,geopoint(37.738767,-122.424037))”)
.build();
Query Query=Query.newBuilder().setOptions(options).build(“距离(myGeoPoint,geopoint(37.738767,-122.424037))<10000”);
结果=空;
试一试{
结果=index.search(查询);
对于(ScoredDocument文档:结果){
列表表达式=document.getExpressions();
for(字段e:表达式){
System.out.println(“表达式=”+e);
}
}
}捕获(搜索异常){
if(StatusCode.TRANSIENT_ERROR.equals(
e、 getOperationResult().getCode()){
结果=index.search(查询);
}
}
这是我在输出中看到的(而不是HTML,我希望calculatedDistance是带有有效数值的数字):


expression=Field(name=calculatedDistance,value=,type=HTML)

我已经这样做了(将距离值作为一个表达式返回),并且效果很好。我在这里编写了一个PHP包装器库来实现这一点,但我将尝试挖掘它生成的有效查询。因此,我检查了查询,第一次查看时它似乎与您的查询完全相同!可能在没有返回字段列表的情况下尝试?在没有指定返回字段列表的情况下尝试,但HTML输出同样不正确。我正在开发环境中测试这个,因为我没有看到Google[link]()提出的任何限制。FieldExpression中的此距离函数调用是否仅适用于生产应用程序引擎?