我正在使用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
但同样的错误。对此有何帮助?
我已经在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请求中,如我们的文档中所示。