How to order documents by distance when using Collection(Edm.GeographyPoint) on the documents

雨燕双飞 提交于 2019-12-13 03:48:43

问题


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.

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 query

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/57736116/how-to-order-documents-by-distance-when-using-collectionedm-geographypoint-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!