I am using Solr 7.6 for Searching and filtering. I want to filter data nearby location using Solr Spatial Search but can't find any data.

I have done the following changes in schema.xml:

<fieldType name="location" class="solr.LatLonPointSpatialField" docValues="true" />
<field name="latlong" type="location" indexed="true" stored="true"/>

I've tried this query :

d=5&fq={!geofilt sfield=latlong}&pt=22.303894, 70.802162&q=*:*

my response :

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"*:*",
      "d":"5",
      "pt":"22.303894, 70.802162",
      "fq":"{!geofilt sfield=latlong}",
      "_":"1556533385742"}},
  "response":{"numFound":0,"start":0,"docs":[]
  }}

Expected Document:

{
        "zipCode":"360001",
        "currencySign":"₹",
        "suspendedByAdmin":false,
        "likeCount":62,
        "id":1372,
        "longitude":70.8023621,
        "countryname":"India",
        "statename":"Gujarat",
        "suspended":false,
        "city":"Rajkot",
        "latitude":22.2913494,
        "description":"Description is here"
        "_version_":1632151597023756288},

1 Answers

0
Mansi Joshi On Best Solutions

Finally got the solution. Firstly put the latlong value as text(lat,long) and then assign that latlong value as a location, this is use as sfield for geospatial query

<fieldType name="location" class="solr.LatLonPointSpatialField" docValues="true" />
<field name="latlong" type="text_general" indexed="true" stored="false" multiValued="false"/> 
<field name="location" type="location" indexed="true" stored="true" multiValued="false"/>

using copyField it store value of latlong

<copyField source="latlong"  dest="location"/>

Query:

  d=5&fq={!geofilt sfield=location}&pt=22.303894,70.802162&q=*:*

Response:

 {
      "responseHeader":{
        "status":0,
        "QTime":1,
        "params":{
          "q":"*:*",
          "d":"5",
          "pt":"22.303894,70.802162",
          "fq":"{!geofilt sfield=store}",
          "_":"1557114448320"}},
      "response":{"numFound":15,"start":0,"docs":[
          {
            "zipCode":"360003",
            "currencySign":"₹",
            "suspendedByAdmin":false,
            "likeCount":45,
            "id":509,
            "longitude":70.8147741,
            "latlong":"22.3024966,70.8147741",
            "_version_":1632752689826758656,
            "store":"22.3024966,70.8147741},
         {...