在文档上使用Collection(Edm.GeographyPoint)时如何按距离排序文档 [英] How to order documents by distance when using Collection(Edm.GeographyPoint) on the documents

查看:51
本文介绍了在文档上使用Collection(Edm.GeographyPoint)时如何按距离排序文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引,其中包含不同的产品.每个产品可在许多商店中购买.索引的一个字段是 Collection(Edm.GeographyPoint),其中保存有该产品所在商店的坐标.

I have an index with different products. Each product is available in many stores. One field of the index is a Collection(Edm.GeographyPoint) wich holds the coordinates of the stores where the product is available.

一些导入到索引中的示例数据(CSV):

Some example data (CSV) that´s imported in the index:

"product","vendor","coordinates"
"Coca Cola 0.5l","Billa","[{ ""type"": ""Point"", ""coordinates"": [48.1184669,16.2030506]},{ ""type"": ""Point"", ""coordinates"": [48.1184977,16.1877297]},{ ""type"": ""Point"", ""coordinates"": [48.1340644,16.2809381]}]"
"Nöm Mix Joghurt 250mg","Billa","[{ ""type"": ""Point"", ""coordinates"": [48.1184669,16.2030506]},{ ""type"": ""Point"", ""coordinates"": [48.1184977,16.1877297]},{ ""type"": ""Point"", ""coordinates"": [48.1340644,16.2809381]}]"
"Red Bull Dose 250ml","Billa","[{ ""type"": ""Point"", ""coordinates"": [48.1184669,16.2030506]},{ ""type"": ""Point"", ""coordinates"": [48.1184977,16.1877297]},{ ""type"": ""Point"", ""coordinates"": [48.1340644,16.2809381]}]"

现在,我想按距离对查询结果进行排序.

Now I want to sort the results of a query by distance.

搜索查询

search=red bull&$count=true&$orderby=geo.distance(coordinates, geography'POINT(48.1078023 16.1692154)') asc

如果我在每个数据集中有一个地理点,那很好用,但是一旦它是一个点集合,我就会收到以下错误:

That works fine if I have a single geographic point in each dataset but as soon as it´s a collection of points I get the following error:

"Invalid expression: The argument for an invocation of a function with name 'geo.distance' is not a single value. All arguments for this function must be single values.\r\nParameter name: $orderby"

我的问题是,是否还有另一个地理函数可以让我按集合中的点对数据集进行排序,或者是否必须对我的数据结构使用其他模式.

My question is if there is another geo function which allows me to order the datasets by the points in a collection or if I have to use another pattern for my data structure.

推荐答案

无法在Azure搜索中按集合字段(包括地理点字段)进行排序.

There is no way to sort by collection fields in Azure Search, including geo-point fields.

启用此功能所需的某种方式是,在集合字段上进行汇总,以为要排序的每个文档生成单个值.例如,如果要按一组数字排序,则必须选择是按它们的平均值,最小值,最大值,总和或某些其他汇总函数排序.对于一个地理空间坐标集合,您希望采用哪种聚合方式还不清楚.

What would be needed to enable this is some way to aggregate over a collection field to produce a single value for each document on which to sort. For example, if you wanted to sort by a collection of numbers, you'd have to choose whether to sort on their average, minimum, maximum, sum, or some other aggregate function. It's less clear what aggregation you'd want for a collection of geospatial co-ordinates.

由于Azure搜索不支持在排序过程中聚合集合的概念,因此今天无法按集合对文档进行排序.如果您的目标是对商店而不是产品进行排序(每个商店都有一个地理位置),那么我建议为商店创建第二个索引.

Since Azure Search does not support this concept of aggregating collections during sorting, it isn't possible to sort documents by collections today. If your goal is to sort stores and not products, where each store has a single geo-location, then I recommend creating a second index for stores.

这篇关于在文档上使用Collection(Edm.GeographyPoint)时如何按距离排序文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆