将地理位置搜索查询与距离过滤/排序相结合的任何示例?

问题描述 投票:2回答:1

我正在使用gocb来查询基于地理位置的文档。到目前为止,NewGeoDistanceQuery与该指数配合得很好。现在我需要根据地理位置距离对结果进行排序。根据here的文档,它说我需要在查询中传递sort参数!但是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但同样的错误。对此有何帮助?

go sdk couchbase gocb
1个回答
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请求中,如我们的文档中所示。

© www.soinside.com 2019 - 2024. All rights reserved.