1.核心代码:
for(SolrDocument doc:docs){
String eId=doc.getFieldValue("enterpriseId")==null?"":doc.getFieldValue("enterpriseId").toString();
System.out.println("企业id:"+eId);
Map<String, Object> valMap = doc.getFieldValueMap();
SolrInputDocument solr = new SolrInputDocument();
for (String c : valMap.keySet()) {
if(c.equals("enterpriseName")){
String value=(String)valMap.get(c);
System.out.println("转换前:"+value);
value=value.replace(" ", "").replace(" ", "");
System.out.println("转换后:"+value);
solr.addField(c, value);
}
if(c.equals("createDate")){
solr.addField("createDate",DateUtils.SOLR_SDF.format(new Date()));//生成时间
}
else{
solr.addField(c, valMap.get(c));
}
docsList.add(solr);
}
}
文件见百度网盘