Can Solr DIH do atomic updates?`

£可爱£侵袭症+ 提交于 2019-11-30 09:59:41

The answer is "yes" with the ScriptTransformer, I discovered through trial and error.

The Solr documentation shows how to add an update attribute to a field node with "set", "add" or "inc". If I create a test XML file with the requisite update attribute, it works fine when passed to the regular update handler. But, when passed to DIH - even without any transformation - the update attributes get ignored completely.

Here's a simplified version of the script transformer I used to reintroduce the update attribute and get atomic updates working. Note the use of the Java HashMap.

var atomicTransformer = function (row) {
    var authorMap = new java.util.HashMap();
    var author = String(row.get('author'));
    authorMap.put('add', author);
    row.put('author', authorMap);
};

This produces the following JSON in DIH debug mode:

{
    "id": [
        123
    ],
    "author": [
        {
            "add": "Smith, J"
        }
    ]
}

Multivalued fields are also no problem: pass in an ArrayList to the HashMap instead of a string.

var atomicTransformer = function (row) {
    var fruits = new java.util.ArrayList();
    fruits.add("banana");
    fruits.add("apple");
    fruits.add("pear");
    var fruitMap = new java.util.HashMap();
    fruitMap.put('add', fruits);
    row.put('fruit', fruitMap);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!