我有一些 XML可以摄入到Solr中,这听起来像是一个旨在由DataImportHandler解决的用例.我想要做的是从一个XML属性中提取列名,从另一个属性中提取值.这是我的意思的一个例子: document data r
<document>
<data ref="reference.foo">
<value>bar</value>
</data>
</document>
从这个xml片段,我想添加一个名称为reference.foo和值栏的字段. DataImportHandler包含一个用于处理XML文档的XPathEntityProcessor.我已经尝试过使用它,如果我给它一个已知的列名称(例如,< field column =“ref”xpath =“/ document / data / @ ref”>)但它无法找到任何文档或示例,以建议如何做我想要的,或无法完成.所以:
>我可以使用XPathEntityProcessor执行此操作吗?如果是这样,怎么样?
>如果没有,我可以使用DataImportHandler以其他方式执行此操作吗?
>还是我离开了写自己的导入处理程序?
...
<script>
function makePair(row) {
var theKey = row.get("theKey");
var theValue = row.get("theValue");
row.put(theKey, theValue);
row.remove("theKey");
row.remove("theValue");
return row;
}
</script>
...
<entity name="..."
processor="XPathEntityProcessor"
transformer="script:makePair"
forEach="/document"
...>
<field column="theKey" xpath="/document/data/@ref" />
<field column="theValue" xpath="/document/data/value" />
</entity>
...
希望有人帮助!
请注意,如果您的dynamicField是多值的,则必须遍历theKey,因为row.get(“theKey”)将是一个列表.
