solr 数据源导入需要注意的问题 dataimport.xml

配置data-conf.xml配置文件时注意大小写。

	<document name="faq">
		<entity name="t_faq" dataSource="jdbc" pk="id"
			transformer="ClobTransformer" query="select * from im_ry_faq t">
			<field column="id" name="id" />
			<field column="question" name="question" />
			<field column="ANSWER" name="answer" clob="true" />
			<field column="key_word" name="keywords" />
		</entity>
	</document>

 ANSWER如果改成小写,那么ClobTransformer是不会被执行解析的。

 

看solr如下代码

public Object transformRow(Map<String, Object> aRow, Context context) {
    for (Map<String, String> map : context.getAllEntityFields()) {
      if (!TRUE.equals(map.get(CLOB))) continue;
      String column = map.get(DataImporter.COLUMN);
      String srcCol = map.get(RegexTransformer.SRC_COL_NAME);
      if (srcCol == null)
        srcCol = column;
      Object o = aRow.get(srcCol);
      if (o instanceof List) {
        List<Clob> inputs = (List<Clob>) o;
        List<String> results = new ArrayList<String>();
        for (Object input : inputs) {
          if (input instanceof Clob) {
            Clob clob = (Clob) input;
            results.add(readFromClob(clob));
          }
        }
        aRow.put(column, results);
      } else {
        if (o instanceof Clob) {
          Clob clob = (Clob) o;
          aRow.put(column, readFromClob(clob));
        }
      }
    }
    return aRow;
  }
  Object o = aRow.get(srcCol);如果填写小写是获取不到对象。那么就不会被 ClobTransformer即使你配置了也是无效的

你可能感兴趣的:(xml,jdbc,Solr)