简体   繁体   English

是否可以在Google搜索API中将文档字段用作带有距离功能的半径?

[英]Is it possible to use a document field as radius with distance function in Google search API?

I have stored circular approximations of trajectory data as documents via the Google Search API . 我已经通过Google Search API将轨迹数据的圆形近似值存储为文档。 That means I am calculating the circumcircle around an arbitrary trajectory and storing the middle point as geo point field with longitude and latitude into the document. 这意味着我正在计算围绕任意轨迹的外接圆,并将中点作为具有经度和纬度的地理位置字段存储到文档中。 In addition to that I save the radius of the circle as number field. 除此之外,我将圆的半径另存为数字字段。

Now I want to query my documents in the following way: 现在,我想通过以下方式查询我的文档:

"distance(middlePoint, geopoint(35.2, 40.5)) <= radius"

I want to use the distance function with a fixed location in longitude and latitude and the field where I stored the circle middle. 我想将距离函数用于经纬度的固定位置以及存储圆心的字段。 So far, so good. 到现在为止还挺好。 The problem seems to be that I cannot use a field (in my case the circle radius) as comparative value for the distance. 问题似乎是我不能使用字段(在我的情况下为圆半径)作为距离的比较值。

However, I do not get any exceptions when I am trying to execute the query. 但是,当我尝试执行查询时,没有任何异常。 It's just seems that the radius field does not get interpreted and I never receive any results from the query. 似乎半径字段未得到解释,而且我从查询中从未收到任何结果。

I've been googling a lot now and also studied the documentation carefully but I did not find any hint that my kind of query really is impossible. 我现在一直在搜索很多东西,并且也仔细研究了文档 ,但是我没有发现暗示我的查询确实是不可能的。

The background of my query is that I kinda want to invert the usual query of the form "Find all points that are in a specific radius from a given point" to a query like "Find all circles that contain a given point in their circumference". 查询的背景是,我有点想将“查找从给定点到特定半径范围内的所有点”形式的常规查询转换为“查找在圆周上包含给定点的所有圆”的查询。

Has anyone ever tried something like this or can provide some information why the query is not working? 有没有人尝试过这样的事情,或者可以提供一些信息为什么查询不起作用? I am also open for alternative solutions for my query. 我也愿意为我的查询提供替代解决方案。

The search API does not support queries on the form fieldname = other_fieldname . 搜索API不支持对fieldname = other_fieldname格式的查询。 Everything on the right side of the relational operator is interpreted as a constant to search for. 关系运算符右侧的所有内容都解释为要搜索的常量。

How big is the maximum possible radius compared to the smallest possible one? 最大可能半径与最小可能半径有多大? If the difference isn't unreasonably big, perhaps one viable implementation would be do your query with the maximum possible radius and then do a second filtering pass in your own code to get down to the desired radius. 如果差异不算过大,也许一个可行的实现是使用最大可能的半径进行查询,然后在您自己的代码中进行第二次过滤以降低到所需的半径。 Perhaps also use a Sort Expression to sort the results by the distance between middlePoint and the input point. 也许还可以使用“排序表达式”来按middlePoint和输入点之间的距离对结果进行排序。 Might help failing faster. 可能会帮助您更快地失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM