如何从dataimporthandler访问父行

时间:2013-06-19 09:20:57

标签: java solr dataimporthandler transformer

我想为dataimporthandler创建一个自定义转换器。我想访问父实体的行。我怎样才能做到这一点。有可能吗?

  @Override
  public Object transformRow(Map<String, Object> row, Context context) {

    LOG.info("##gyk: row: {}",row);

    //******What to do here? ********
    LOG.info("##gyk: PARENT-ROW: {}", ????);


    return row;
  }

更新

我目前的解决方法是使用会话变量

  @Override
  public Object transformRow(Map<String, Object> row, Context context) {

    if (context.isRootEntity()) {

      Object tmp = row.get("Keywords");
      if (tmp == null) return row;

      String[] kwArray = tmp.toString().split(",");

      HashSet<String> kwSet = new HashSet<String>(64);

      for (String kw : kwArray) {
        kwSet.add(kw.trim().toLowerCase());
      }
      LOG.info("##gyk: root entity kw: {}",kwSet);

      context.setSessionAttribute("company-keywords-set", kwSet, "document");

    } else {
      LOG.info("##gyk: row: {}",row);

      HashSet<String> companyKeywordSet = (HashSet<String>)context
          .getParentContext().getParentContext()
          .getSessionAttribute("company-keywords-set", "document");

      if (companyKeywordSet != null) {
        LOG.info("##gyk: keywords from parent: {}", companyKeywordSet);
      }

    }

    return row;
  }

更新

当我尝试记录此context.getParentContext().getParentContext().getAllEntityFields()时,我得到以下内容: [{multiValued=false, toWrite=true, indexed=true, name=id, column=FIR_NR, boost=1.0, defaultValue=null, stored=true, type=string}, {multiValued=false, toWrite=true, indexed=true, name=fir_name, column=FIR_NAME, boost=1.0, defaultValue=null, stored=true, type=text_general}]

这些只是该实体的字段定义。

0 个答案:

没有答案