简体   繁体   English

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

[英]how to filter query multivalued location attribute in solr

I'm trying to set up Solr Geospatial searching in my application. 我试图在我的应用程序中设置Solr Geospatial搜索。 The model is that I've got customer with multiple addresses, and I want to tag that customer with each address geocode, then search for customers within a distance from a center point. 该模型是,我有多个地址的客户,并且我想用每个地址地理代码标记该客户,然后在距中心点一定距离内搜索客户。

It works okay with one geocode. 只需使用一个地理编码即可。 Here is what I have in schema so far for multiple geocodes per solr entry: 到目前为止,这是我在架构中针对每个solr条目的多个地理编码的内容:

In Schema.xml 在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" />

This is fine, although when I query the docs through SOLR admin I can only see the values for the individual coordinate fields, not for the location. 这很好,尽管当我通过SOLR管理员查询文档时,我只能看到各个坐标字段的值,而不能看到位置的值。 Is there a way I can fix that bit? 有办法解决这个问题吗?

But the bigger problem is that when I execute this SOLR query: 但是更大的问题是当我执行此SOLR查询时:

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

It errors with: 出现以下错误:

"can not use FieldCache on multivalued field: latlng_0_coordinate"

I believe this is caused by trying to execute a filter query against a multi-valued attribute generally. 我认为,这是由于尝试对多值属性执行过滤查询所致。

I tried this from the solr admin panel: 我在solr管理面板中尝试了此操作:

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

but it just returns all documents... 但是它只返回所有文档...

So I was wondering if there's an alternative way to query against a multi-valued location parameter? 所以我想知道是否还有另一种方法可以查询多值位置参数?

Ok I got the answer from a duplicate question here: Search in solr with multivalued location field 好的,我从一个重复的问题中得到了答案: 在带有多值位置字段的solr中搜索

So the interesting part that I'll include in this answer though is that I used the DIH to import the lat long. 因此,我将在此答案中包括的有趣部分是,我使用DIH长时间导入了lat。 So you can import the field directly using the fields separated by spaces: 因此,您可以使用以空格分隔的字段直接导入字段:

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

This new type is SOLR 4 type by the look of it, and supports the filter query on the multi-valued attribute. 从外观上看,此新类型为SOLR 4类型,并支持对多值属性的过滤器查询。

So my schema looks more like this now: 所以我的架构现在看起来像这样:

<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" />

Then the filter query from SOLR 4 works as expected. 然后,来自SOLR 4的过滤器查询将按预期工作。

Very happy this is solved, it's a big win and critical piece for my application! 很高兴这个问题得以解决,这对我的应用来说是一个巨大的胜利,也是至关重要的一环!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM