微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为索引多边形形状返回的距离不正确

如何解决为索引多边形形状返回的距离不正确

我在 Solr 查询中使用 geodist()。按照这个select?=&fl=*,_dist_:geodist()&fq={!geofilt d=30444}&indent=on&pt=50.53,-9.5722616&q=*:*&sfield=geo&spatial=true&wt=json 但是,距离计算似乎不起作用。这是一个示例查询,其中 pt 距离 polyGON 数百公里。计算的geodist总是20015.115的问题。

这是我的查询回复

{
  "responseHeader":{
    "status":0,"QTime":0,"params":{
      "q":"*:*","pt":"50.53,-9.5722616","indent":"on","fl":"*,_dist_:geodist()","fq":"{!geofilt d=30444}","sfield":"geo","spatial":"true","wt":"json"}},"response":{"numFound":3,"start":0,"docs":[
      {
        "id":"1","document_type_id":"1","geo":["polyGON ((3.837490081787109 43.61234105514181,3.843669891357422 43.57877424689641,3.893280029296875 43.57205863840097,3.9458084106445312 43.58872191986938,3.921947479248047 43.62762639320158,3.8663291931152344 43.63321761913266,3.837490081787109 43.61234105514181))"],"_version_":1689241382273679360,"timestamp":"2021-01-18T16:08:40.484Z","_dist_":20015.115},{
        "id":"4","document_type_id":"4","geo":["polyGON ((-0.94482421875 45.10454630976873,-0.98876953125 44.6061127451739,0.06591796875 44.134913443750726,0.32958984375 45.1510532655634,-0.94482421875 45.10454630976873))"],"_version_":1689244486784253952,"timestamp":"2021-01-18T16:58:01.177Z",{
        "id":"8","document_type_id":"8","geo":["polyGON ((-2.373046875 48.29781249243716,-2.28515625 48.004625021133904,-1.5380859375 47.76886840424207,-0.32958984375 47.79839667295524,-0.5712890625 48.531157010976706,-2.373046875 48.29781249243716))"],"_version_":1689252312264998912,"timestamp":"2021-01-18T19:02:24.137Z","_dist_":20015.115}]
  }}

这是我的 solr 字段类型定义:

<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" maxdistErr="0.001" 

spatialContextFactory="org.locationtech.spatial4j.context.jts.JtsspatialContextFactory" 
validationRule="repairBuffer0"
distErrPct="0.025"
distanceUnits="kilometers"
autoIndex="true"/>

<field name="geo" type="location_rpt" multiValued="false" indexed="true" stored="true"/>

这就是我索引多边形的方式:

{
  "id": 12,"document_type_id": 12,"geo": "polyGON ((3.77105712890625 43.61171961774284,3.80401611328125 43.57939602461448,3.8610076904296875 43.59580863402625,3.8603210449218746 43.61519958447072,3.826675415039062 43.628123412124616,3.7827301025390625 43.63110543935801,3.77105712890625 43.61171961774284))"
}

我使用的是 Solr 6.6,我发现了 2 个关于此的问题:

这可能是什么原因?

解决方法

score=distance(或其他类似距离的选项)用于索引 RPT 中的点或使用 BBoxField 的框(矩形)。为此,它有效。如果您在 RPT 中索引非点数据,结果将是错误的并且 geodist 将始终返回 20015.115

最好的快速解决方案是添加另一个具有 location 类型的字段并通过 geodist 执行距离计算,例如:

<field name="geo" type="location_rpt" multiValued="true" indexed="true" stored="true"/>
<field name="geo_for_disatance" type="location" indexed="true" required="false" stored="false"/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。