Closing the loop here (I think you reached out to me in multiple other
channels) -- Solr only supports calculating the distance between points.
If you manage to index your data with a centroid point and a separate
numeric field that is an approximate radius, you can get something that may
be good enough for what you want to do.  Basically, calculate the geodist
but subtract the radius field... maybe something like this (untested!):
sort=sub(geodist(),radius) desc.  Use LatLonPointSpatialField to store
point data if you can (is appropriate), which succeeded RPT for that.

~ David Smiley
Apache Lucene/Solr Search Developer
http://www.linkedin.com/in/davidwsmiley


On Wed, Jan 20, 2021 at 6:00 AM Famas <ahmedbhs...@gmail.com> wrote:

> 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:
> ```xml
> <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:
>
> ```json
> {
>   "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))"
> }
> ```
>
> By the way I'm using solr 6.6 and I found 2 issues about this :
>
> https://issues.apache.org/jira/browse/SOLR-12899 <br>
> https://issues.apache.org/jira/browse/SOLR-12899
>
> Does there an explanation !?
> Any help would be appreciated!
>
>
>
> --
> Sent from: https://lucene.472066.n3.nabble.com/Solr-User-f472068.html
>

Reply via email to