rat*_*tar 4 solr dataimporthandler
我有一些XML可以摄入到Solr中,这听起来像是一个旨在由DataImportHandler解决的用例.我想要做的是从一个XML属性中提取列名,从另一个属性中提取值.这是我的意思的一个例子:
<document>
<data ref="reference.foo">
<value>bar</value>
</data>
</document>
Run Code Online (Sandbox Code Playgroud)
从这个xml片段,我想添加一个名称reference.foo和值的字段bar.DataImportHandler包含一个用于处理XML文档的XPathEntityProcessor.我已经尝试过使用它,如果我给它一个已知的列名称(例如<field column="ref" xpath="/document/data/@ref">),但它无法找到任何文档或示例来建议如何做我想要的,或者它无法完成.所以:
我没有设法在没有引入变压器的情况下找到这样做的方法,但是通过使用简单的方法ScriptTransformer我已经完成了.它是这样的:
...
<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>
...
Run Code Online (Sandbox Code Playgroud)
希望有人帮助!
请注意,如果您的dynamicField是多值的,则必须遍历theKey,因为row.get("theKey")将是一个列表.
| 归档时间: |
|
| 查看次数: |
2789 次 |
| 最近记录: |