以下是我如何获得所需距离的所有项目:
query_string = 'distance(LocationCoord, geopoint(35.2, 40.5)) < 1000'
query_options = search.QueryOptions(
returned_fields=['ID', 'GUID', 'LocationCoord', '**distance()**']
)
query = search.Query(query_string=query_string, options=query_options)
res = index.search(query)
我如何实际返回搜索结果中的距离?
答案 0 :(得分:1)
为此,您可以添加FieldExpression:
query_string = 'distance(LocationCoord, geopoint(35.2, 40.5)) < 1000'
expression = search.FieldExpression(name='distance', expression='distance(LocationCoord, geopoint(35.2, 40.5))')
query_options = search.QueryOptions(
returned_fields=['ID', 'GUID', 'LocationCoord']
returned_expressions=[expression],
)
query = search.Query(query_string=query_string, options=query_options)
res = index.search(query)