结合地理位置搜索查询和距离过滤器/排序的任何示例吗?

时间:2019-04-28 06:25:25

标签: go sdk couchbase gocb

我正在使用gocb根据地理位置查询文档。到目前为止,NewGeoDistanceQuery与索引配合良好。现在,我需要根据地理位置距离对结果进行排序。根据{{​​3}}中的文档,它说我需要在查询中传递排序参数!但是NewGeoDistanceQuery没有。因此搜索了sdk,发现NewSearchSortGeoDistance正是我在寻找的东西,但是我对如何组合它们感到困惑。

    location := cbft.NewGeoDistanceQuery(in.Lat, in.Lon, fmt.Sprintf("%skm", in.Distance))
    sort := cbft.NewSearchSortGeoDistance("address", in.Lat, in.Lon).Unit("km")
    conjunctionQuery = cbft.NewConjunctionQuery(location, sort)

我尝试了上面的解决方案,但出现了此错误

{"error":"rest_index: Query, indexName: restaurant-geo-search, err: bleve: QueryBleve parsing searchRequest, err: unknown query type","request":{"ctl":{"timeout":75000},"query":{"conjuncts":[{"distance":"2km","location":[90.404272,23.793993]},{"by":"geo_distance","field":"address","location":[90.404272,23.793993],"unit":"km"}]},"size":100},"status":"fail"}

我还尝试过单独使用NewSearchSortGeoDistance,但存在相同的错误。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

我已经在https://forums.couchbase.com/t/any-example-for-combining-geo-location-search-query-with-distance-filter-sorting/21155回答了,但也只是将所有信息放在这里:

我认为这里的问题是您试图将排序顺序用作查询,而不是用作排序标准。我认为您想要的可能是gocb.NewSearchQuery(indexName, location).Sort(sort)。如我们的文档所示,这将采用排序标准并将其放入sort字段下的JSON请求中。