【问题标题】:distance function of Google AppEngine Search API is behaving unconsistantlyGoogle AppEngine Search API 的距离函数表现不一致
【发布时间】:2014-04-25 04:54:39
【问题描述】:
    String loc_expr = "distance(location, geopoint(" + userLatitude + ", " + userLongitude + "))";

    // Build the SortOptions
    SortOptions sortOptions = SortOptions.newBuilder()
            .addSortExpression(SortExpression.newBuilder().setExpression(loc_expr).setDirection(SortExpression.SortDirection.ASCENDING).setDefaultValueNumeric(0))
            .setLimit(200).build();

    // Build the QueryOptions
    QueryOptions options = QueryOptions.newBuilder().addExpressionToReturn(FieldExpression.newBuilder().setExpression(loc_expr).setName("distance")).setLimit(limit)
            .setCursor(cursor).setSortOptions(sortOptions).build();

    String queryString = loc_expr + " < " + searchRadius * 1000;

    // Build the Query and run the search
    Query query = Query.newBuilder().setOptions(options).build(queryString);

    IndexSpec indexSpec = IndexSpec.newBuilder().setName("restaurants").build();
    Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);

    Results<ScoredDocument> result = index.search(query);
    if (result.getNumberFound() > 0) {
        Collection<ScoredDocument> coll = result.getResults();

        for (ScoredDocument sd : coll) {
            Key<Restaurant> key = Key.create(String.valueOf(sd.getId()));
            Restaurant rest = ofy().load().key(key).now();

            Field f = sd.getExpressions().get(0);
            log.info("distance in meter : " + f.getNumber());
        }
    }

我正在使用上述代码来获取附近地区的餐馆。以下是我的观察:-

案例1:searchRadius = 0.5 km --- 距离最大值= 0.9 km

案例2:searchRadius = 1 km --- 距离最大值= 1.8 km

案例3:searchRadius = 2 km --- 距离最大值= 2.8 km

案例4:searchRadius = 3 km --- 距离最大值 = 4.8 km

为什么我得到的距离值大于指定的半径?

注意 :- 我不是自己计算距离。搜索 API 正在返回距离。

【问题讨论】:

    标签: google-app-engine google-search-api


    【解决方案1】:

    这是一个已知的issue

    在 Google 修复它之前,您必须在代码中过滤结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多