多值PointType字段的空间查询

时间:2014-04-03 22:01:28

标签: solr spatial

我在查询多值PointType字段时遇到问题。这可以在Solr中正确完成。

示例文件:

<doc>
    <field name="id">test1</field>
    <field name="xy">100,100</field>
    <field name="xy">0,100</field>
    <field name="xy">100,0</field>
    <field name="xy">0,-100</field>
    <field name="xy">-100,0</field>
    <field name="xy">-100,-100</field>
    <field name="xy">-100,100</field>
    <field name="xy">100,-100</field>
</doc>

架构:

<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
<field name="xy" type="point" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_d" type="double" indexed="true" stored="true" multiValued="true"/>

FQuery:

{!geofilt pt=0,0 sfield=xy d=15}

它不应该与文档匹配,但确实如此:(

我的目标是查询该XY字段以获取按距离排序的文档(在某些时候,它希望在地理查询之间或每个子查询中的总和得分以计算doc的最终得分)。

任何想法都可以这样做(简单的查询atm)?

1 个答案:

答案 0 :(得分:1)

{!geofilt}不适用于多值

http://wiki.apache.org/solr/SpatialSearch#LatLonType

但幸运的是有一个新功能,即SpatialRecursivePrefixTreeFieldType(缩写为RPT)。这是SOLR 4.0及更高版本,因此首先检查您的solr版本,如果您仍在使用3.x版本,请进行升级。

您需要定义rpt字段类型

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

然后您可以在多值字段中使用它

<field name="point" type="location_rpt" indexed="true" stored="true"  multiValued="true" />

现在你需要以不同的方式编写你的查询:

fq=geo:"Intersects(Circle(point d=1.5))"

确保将距离转换为度数(而不是公里数)。 这是从公里转换为度数的快速方法

distantceInDegrees = distanceInKilometers / 111.2

有关查询的更多信息:

https://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4