Solr空间搜索使用索引字段进行半径? [英] Solr spatial search using an indexed field for radius?

查看:220
本文介绍了Solr空间搜索使用索引字段进行半径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个城市的索引,看起来像这样:

  {
location: 41.388587,2.175888,
name:BARCELONA,
radius:20
}

我们有几十个。我需要能够使用一个单一的lat / lng组合查询该索引,并查看它是否落入我们的城市之一。



位置属性是城市的中心,而半径是以km为单位的城市半径(假设所有城市都是圆形)。我们也可以假定没有任何城市重叠。



如何将一个拉丁/联盟组合置于城市之内? >

例如,给定点$ code> 40.419691,-3.701254 ,如何判断是否属于BARCELONA?

解决方案

您可以轻松地在Lucene,Solr或ES中执行。



在Solr中,例如:


  1. 声明一种SpatialRecursivePrefixTreeFieldType类型。这样,您可以使用lat / long和半径为不同的形状索引不同的形状,而不仅仅是点

  2. ,您可以为每个城市创建一个特定的圈子,然后在一个称为形状的字段,例如:

      {
    location:41.388587,2.175888,
    name:BARCELONA,
    shape:CIRCLE(2.175888 41.388587,20)
    }


  3. 然后您只需查询与您的点相交的任何文档(未测试):

      fq = shape:相交(40.419691 -3.701254)


确保检查您正在使用的特定版本的Lucene / Solr / ES的文档和javadoc,因为API已在此空间中更改


So I have an index of cities, looks something like this:

{
  "location": "41.388587, 2.175888",
  "name": "BARCELONA",
  "radius": 20
}

We have a few dozen of these. I need to be able to query this index with a single lat/lng combination and see if it falls inside one of our "cities".

The location property is the centre of the city, and the radius is the radius of the city in km (assuming all the cities are circles). We can also assume no cities overlap.

How can I return whether or not a lat/lng combination falls within a city?

For example, given the point 40.419691, -3.701254, how can I determine if this falls within BARCELONA?

解决方案

you can do it easily, in either Lucene, Solr or ES.

In Solr for example:

  1. declare a type of SpatialRecursivePrefixTreeFieldType. This allows you to index different shapes, not just points
  2. by using lat/long and the radius, you create an specific circle for each city, and you index that shape, in a field called 'shape' for example:

    {
      "location": "41.388587, 2.175888",
       "name": "BARCELONA",
       "shape": "CIRCLE (2.175888 41.388587, 20)"
    }
    

  3. then you just query for any doc that intersects with your point (untested):

    fq=shape:"Intersects(40.419691 -3.701254)"
    

Be sure to check the docs and javadocs for the specific version of Lucene/Solr/ES you are using, as APIs have been changing in this space

这篇关于Solr空间搜索使用索引字段进行半径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆