具有查询文档距离值的SOLR空间查询

SOLR spatial query with distance value of queried document

我正在尝试对一组具有半径字段和位置字段的文档进行空间查询:

<field name="placeOfWork_coords" type="location" indexed="true" stored="true" required="false" multiValued="false" />
<field name="radius" type="pint" indexed="true" stored="true" required="false" multiValued="false" />

我想检查任意经纬度点是否在该文档的半径范围内。到目前为止,我只使用了 d 查询参数的静态距离,所以我想知道如何在查询中引用文档的半径字段(如果可能的话)。

据我所知,您必须为形状本身编制索引,而不是将其作为两个单独的字段;用给定的中心点和半径索引一个圆。您可以使用 RptWithGeometrySpatialField field, and index your shape as:

Circle(4.56,1.23 d=0.0710)

后一个距离以度为单位,要转换为 miles/km/meters,请使用上面链接的 wiki 上提供的公式:

Units, Conversion

Degrees to desired units: Math.toRadians(degrees) * earthRadiusInTheUnitsYouWant

Degrees to kilometers: degrees * 111.1951

Degrees to miles: degrees * 69.09341

RptWithGeometrySpatialField 应该是最准确的选项。查询时,使用 Intersects 运算符:

&fq={!field f=geo}Intersects(-74.093 41.042)

.. 应该可以。您可能需要 POINT 类型或类似类型来包装坐标,但据我所知这不是必需的。以前它是 lon lat 至少如果没有逗号和 lat,lon 如果有,所以确保使用正确的格式。