【问题标题】:how to filter query multivalued location attribute in solr如何在solr中过滤查询多值位置属性
【发布时间】:2014-10-03 19:45:50
【问题描述】:

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

它适用于一个地理编码。这是迄今为止我在模式中为每个 solr 条目提供多个地理编码的内容:

在 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

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

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

【问题讨论】:

    标签: solr


    【解决方案1】:

    好的,我从这里的重复问题中得到了答案: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 的过滤器查询按预期工作。

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

    【讨论】:

    • 您能否提供任何实时示例以在位置字段中添加多个值?
    猜你喜欢
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2012-02-02
    相关资源
    最近更新 更多