Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What SQL datatype should be used to populate a Solr location (spatial) field when using a DataImportHandler?

I have a Solr schema which contains a location field (using the default solr.LatLonType ):

<field name="latlng" type="location" indexed="true" stored="true"/>

And I am trying to populate it using a DataImportHandler. Currently I SELECT the value as nvarchar in the format of 17.74628,-64.70725; however it is not populating the Solr field (it remains empty).

What type and format should this column be in to update the location field in Solr?

like image 579
STW Avatar asked Sep 13 '11 21:09

STW


2 Answers

solr.LatLonType is a multi-dimensional type; You can define the field type as:

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

Using your field name of "latlng" the schema for the coordinate fields will look like this (notice the "subFieldSuffix" used for the 2 dimensional field type solr.LatLonType):

<field name="latlng" type="location" indexed="true" stored="true" />
<field name="latlng_0_coordinate" type="double" indexed="true" stored="true" />
<field name="latlng_1_coordinate" type="double" indexed="true" stored="true" />

"latlng_0_coordinate" should be the latitude and "latlng_1_coordinate" should be the longitude. Your select statement should load "latlng_0_coordinate" and "latlng_1_coordinate" as doubles.

like image 97
Mobius009 Avatar answered Oct 25 '22 20:10

Mobius009


the previous answer works since you're manually creating the fields that Solr uses to store the lat and long individually, however there's a dynamic field for that purpose.

<!-- Type used to index the lat and lon components for the "location" FieldType --> <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false" />

If you check field type location, you might find it uses the suffix _coordinate for their values:

<!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

that works for me in Solr 4 beta, and I believe is present since Solr 3.6 or even older. Anyway, just another solution!

Hope this helps.

like image 40
Carlos Rivera Avatar answered Oct 25 '22 21:10

Carlos Rivera