Search code examples
localizationsolrdih

How can I convert 2 strings to Solr location data field using DIH or copyfiled or sql cast operator?


I have in schema.xml the followings:

<field name="x_geo_x_coordinate" type="double" indexed="true" stored="true" default="0"/>
<field name="x_geo_y_coordinate" type="double" indexed="true" stored="true" default="0"/>
<field name="x_geo" type="location" indexed="true" stored="true" default="0.0,0.0"/>

and I managed to import from a DB the lat, long as strings:

<field name="x_geo_x_str_coordinate_s" type="string" indexed="true" stored="true" default="0"/>
<field name="x_geo_y_str_coordinate_s" type="string" indexed="true" stored="true" default="0"/>
<field name="x_geo_str" type="string" indexed="true" stored="true" multiValued="true" default="0,0"/>

How can I copy/convert the 2 stings in double with a simple solution?

Update 1: Ok, the convertion from string to double has worked corectly, and thanks a lot for the solution! What I have now is the two double filds:

<field name="x_geo_x_coordinate" type="double" indexed="true" stored="true" default="0"/> 
<field name="x_geo_y_coordinate" type="double" indexed="true" stored="true" default="0"/>

and what I want: the 2 double value in one location field:

<field name="x_geo" type="location" indexed="true" stored="true" default="0.0,0.0"/>

What I tried so far and does't work:

<copyField source="*_coordinate" dest="x_geo"/>
<copyField source="x_geo_str" dest="x_geo"/>

Any simple solution? Thanks in advance!


Solution

  • You can use the copyField as follows in your schema.xml file:

      <copyField source="x_geo_x_str" dest="x_geo_x_coordinate"/>
      <copyField source="x_geo_y_str" dest="x_geo_y_coordinate"/>
      <copyField source="x_geo_str" dest="x_geo"/>