0
votes

I'm trying to set up Solr Geospatial searching in my application. 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:

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

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. Is there a way I can fix that bit?

But the bigger problem is that when I execute this SOLR query:

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:

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?

1

1 Answers

0
votes

Ok I got the answer from a duplicate question here: Search in solr with multivalued location field

So the interesting part that I'll include in this answer though is that I used the DIH to import the lat long. 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.

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.

Very happy this is solved, it's a big win and critical piece for my application!