如何在Solr 7.6中配置用于geoSpatial搜索的schema.xml?

时间:2019-04-26 08:07:54

标签: solr geospatial

我正在使用Solr 7.6进行搜索和过滤。我想使用Solr Spatial Search过滤附近位置的数据,但是找不到任何数据。

我在schema.xml中做了以下更改:

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

我已经尝试过此查询:

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

我的回复:

{
  "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":[]
  }}

预期文档:

{
        "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 个答案:

答案 0 :(得分:0)

最后得到了解决方案。 首先将latlong值设为text(lat,long) 然后将该latlong值分配为位置,这将用作地理空间查询的字段

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

使用copyField来存储latlong的值

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

查询:

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

响应:

 {
      "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},
         {...