Solr配置数据列时大小写问题

在solr里配置entity时,没有把field里column的大小写配成和数据库的schema一致,导致有些列的数据一直取不出来,检查好多遍才发现,多花了两个小时。 主要是习惯了hibernate里配置列名时的大小写不敏感。
看了下源码,数据库里复杂类型如datetime,clob列的转换是继承了Transformer类,实现transformRow方法完成的,如Clob字段的转换如下:
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;
      [b]Object o = aRow.get(srcCol);[/b]
      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;
  }

datetime的转换如下:
public Object transformRow(Map<String, Object> aRow, Context context) {
    for (Map<String, String> map : context.getAllEntityFields()) {
      Locale locale = Locale.getDefault();
      String customLocale = map.get("locale");
      if(customLocale != null){
        locale = new Locale(customLocale);
      }

      String fmt = map.get(DATE_TIME_FMT);
      if (fmt == null)
        continue;
      String column = map.get(DataImporter.COLUMN);
      String srcCol = map.get(RegexTransformer.SRC_COL_NAME);
      if (srcCol == null)
        srcCol = column;
      try {
        [b]Object o = aRow.get(srcCol);[/b]
        if (o instanceof List) {
          List inputs = (List) o;
          List<Date> results = new ArrayList<Date>();
          for (Object input : inputs) {
            results.add(process(input, fmt, locale));
          }
          aRow.put(column, results);
        } else {
          if (o != null) {
            aRow.put(column, process(o, fmt, locale));
          }
        }
      } catch (ParseException e) {
        LOG.warn("Could not parse a Date field ", e);
      }
    }
    return aRow;
  }


从Object o = aRow.get(srcCol);可以看出,这些字段都是大小写敏感的了。

你可能感兴趣的:(Solr)