javascriptsolrdataimporthandler

Solr DataImportHandler using ScriptTransformer: JavaScript functionality severely limited


I'm using a simple ScriptTransformer <script> in my db-data-config.xml DataImportHandler. I'd like to decode htmlentities and found I should be using he module. Downloaded the zip and extracted in conf\lib. This is part of my script:

var he = require('./lib/he-master/he.js');
function removeSpecialCharacters(text) {
     if (typeof text !== 'string') {
          return text;
     }
     return he.decode(text);
}

But I get the error:

javax.script.ScriptException: ReferenceError: "require" is not defined in <eval>

Why does nothing work out of the box (like JS require function) and how do I solve this?

It's cheaper to pay than use open source because nothing works out of the box. It takes ages of troubleshooting ($) before something with a little bit of an advanced functionality works.

also tried

eval(readFile('./lib/he-master/he.js');

But it's the same story: nothing is included out of the box with Solr:

javax.script.ScriptException: ReferenceError: "readFile" is not defined in <eval>

Solution

  • I figgered out that the solution is to use load and absolute path:

    load('C:\\solr-8.11.3\\server\\solr\\db\\lib\\he-master\\he.js');