【问题标题】:SOLR spatial query with distance value of queried documentSOLR空间查询与查询文档的距离值
【发布时间】:2020-03-23 16:50:45
【问题描述】:

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

<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 查询参数的静态距离,所以我想知道如何在查询中引用文档的半径字段,如果可能的话。

【问题讨论】:

    标签: solr


    【解决方案1】:

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

    Circle(4.56,1.23 d=0.0710)
    

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

    单位,换算

    度数到所需单位:Math.toRadians(degrees) * earthRadiusInTheUnitsYouWant

    度数以公里为单位:degrees * 111.1951

    度数到英里:degrees * 69.09341

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

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

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

    【讨论】:

    • 我还必须将属性format="LEGACY" 添加到fieldType,如this question 中所回答的那样。否则会出现Unknown Shape definition 错误。
    猜你喜欢
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多