首页 文章

如何在solr中过滤查询多值位置属性

提问于
浏览
0

我正在尝试在我的应用程序中设置Solr Geospatial搜索 . 模型是我有多个地址的客户,我想用每个地址编码标记该客户,然后在距离中心点一定距离内搜索客户 .

它适用于一个地理编码 . 以下是目前针对每个solr条目的多个地理编码的模式:

In Schema.xml

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="true"/>
...
<field name="latlng" type="location" indexed="true" stored="true" multiValued="true" />

这很好,虽然当我通过SOLR管理员查询文档时,我只能看到各个坐标字段的值,而不是位置 . 有没有办法解决这个问题?

但更大的问题是,当我执行此SOLR查询时:

http://localhost:8983/solr/aust/select?q=*:*&fq={!geofilt pt=-37.8064822,144.96090520000007 sfield=latlng d=15}&wt=json&indent=true

它错误:

"can not use FieldCache on multivalued field: latlng_0_coordinate"

我相信这是因为尝试通常对多值属性执行过滤查询 .

我在solr管理面板上试过这个:

http://localhost:8983/solr/aust/select?q=*:*&wt=json&indent=true&spatial=true&pt=-27.516473,152.95089480000001&sfield=latlng&d=20

但它只返回所有文件......

所以我想知道是否有另一种方法来查询多值位置参数?

1 回答

  • 0

    好的,我从这里的重复问题得到答案:Search in solr with multivalued location field

    因此,我将在这个答案中包含的有趣部分是我使用DIH导入lat long . 因此,您可以使用以空格分隔的字段直接导入字段:

    select ..., concat(concat(lng, ' '),lat)... from ...
    

    这个新类型的外观是SOLR 4类型,并支持对多值属性的过滤查询 .

    所以我的架构现在看起来更像这样:

    <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
    
               distErrPct="0.025"
               maxDistErr="0.000009"
               units="degrees" />
    
    <field name="location" type="location_rpt" indexed="true" stored="true" multiValued="true" />
    

    然后来自SOLR 4的过滤器查询按预期工作 .

    很高兴这个问题解决了,这对我的应用来说是一个巨大的胜利和关键作品!

相关问题