【问题标题】:Solr spatial search with input point and query which polygon withinSolr 使用输入点进行空间搜索并查询其中的多边形
【发布时间】:2013-10-22 12:16:47
【问题描述】:

我在 Solr 中有一些多边形索引。是否可以用一个点(纬度,经度)进行查询,看看哪个多边形里面有那个点?

【问题讨论】:

    标签: search solr polygon geospatial point


    【解决方案1】:

    是的,这是可能的,并在此处描述:http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 您的 Solr 版本必须为 4 或更高版本,并且您必须导入可以从 http://sourceforge.net/projects/jts-topo-suite/ 获取的 JTS jar 文件 您必须定义一个 fieldType 为 location_rpt 的字段

    <fieldType name="location_rpt"   class="solr.SpatialRecursivePrefixTreeFieldType"
               spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
               distErrPct="0.025"
               maxDistErr="0.000009"
               units="degrees"
            />
    

    在 schema.xml 中。然后你必须像这样索引多边形:

    <field name="geo">POLYGON((-10 30, -40 40, -10 -20, 40 20, 0 0, -10 30))</field>
    

    但我认为您已经这样做了,因为您写道您已经将它们编入索引。

    对于查询,您只需使用过滤查询fq=geo:"Intersects(10.12 50.02)",其中10.1250.02 代表您点的纬度和经度。

    【讨论】:

    • 为什么需要外部 JTS jar 文件?最新的 SOLR 还需要它吗?
    • 因为从 solr 6.x.x 开始不再包含 JTS 库。只需从这里sourceforge.net/projects/jts-topo-suite 下载 jar 文件并将它们包含到 solr-webapp/webapp/WEB-INF/lib/ 然后重新启动 solr
    【解决方案2】:

    我们首先需要外部 JTS jar 文件来索引多边形形状。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多