In solr dih, import two doubles in one place

Now I have 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: 2 double value in one location field:

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

What I have tried so far and does not work:

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

Any simple solution? Thanks in advance!

+6
source share
4 answers

Well, where are you right @ nikhil500. ScriptTransformer is one answer, (I'm not sure if this is the easiest). The dataconfig.xml file contains a java function:

 <script><![CDATA[ function puttwodouble(row) { var attrVal1 = row.get("GEO_X_WERT"); var attrVal2 = row.get("GEO_Y_WERT"); var attrVal = attrVal1 + "," + attrVal2; var arr = new java.util.ArrayList() arr.add(attrVal1); arr.add(attrVal2); row.put("store",attrVal); row.put("x_geo_str",arr); return row; } ]]> 

whitch will be called:

  <entity name="inner_geo_str" transformer="script:puttwodouble" query="select GEO_X_WERT, GEO_Y_WERT from FIRMA_GEODATEN where GEO_FIR_NR ='${outer.FIR_NR}' and geo_x_wert != 'NF'"> <field column="GEO_X_WERT" name="x_geo_x_s"/> <field column="GEO_Y_WERT" name="x_geo_y_s"/> </entity> 

Hope this helps others solve this problem.

+3
source

Use TemplateTransformer in DIH (data-config.xml):

 <entity name="p" transformer="TemplateTransformer" ...... <field column="location" template="${p.location_0_coordinate},${p.location_1_coordinate}" /> 
+2
source

In addition to PaulG's answer, you can use location_rpt in Solr 4, which supports multiple values, but does not have to be declared as MultiValue.

 <field name="region" type="location_rpt" indexed="true" stored="true" /> 
+2
source

You can use ScriptTransformer to create the x_geo field.

0
source

All Articles