1
votes

I am using geodist() in Solr query. Following this select?=&fl=*,_dist_:geodist()&fq={!geofilt d=30444}&indent=on&pt=50.53,-9.5722616&q=*:*&sfield=geo&spatial=true&wt=json However, it seems like distance calculations aren’t working. Here’s an example query where the pt is several hundred kilometers away from the POLYGON. The problem that the calculated geodist is always 20015.115 .

This is my query response:

{
  "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",
        "_dist_":20015.115},
      {
        "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}]
  }}

This is my solr field type definition:

<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"/>

This is how I index my polygon:

{
  "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))"
}

I'm using Solr 6.6 and I found 2 issues about this :

What might be the reason for this?

1

1 Answers

1
votes

The score=distance (or other distance-like options) is intended for indexing either points in RPT, or boxes (rectangles) with BBoxField. For that it works. If you index non-point data in RPT, the results will be erroneous and geodist gonna return always 20015.115

The best quick solution is to add another field having a location type and perform distance calculation via geodist, for example:

<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"/>