use of de.tblsoft.solr.pipeline.bean.DocumentBuilder in project solr-cmd-utils by tblsoft.
the class JavaScriptFilter method document.
@Override
public void document(Document document) {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
List<Document> output = new ArrayList<Document>();
ScriptableObject.putProperty(scope, "documentBuilder", Context.javaToJS(new DocumentBuilder(), scope));
ScriptableObject.putProperty(scope, "input", Context.javaToJS(document, scope));
ScriptableObject.putProperty(scope, "output", Context.javaToJS(output, scope));
cx.evaluateString(scope, script, filename, 1, null);
for (Document out : output) {
super.document(out);
}
}
use of de.tblsoft.solr.pipeline.bean.DocumentBuilder in project solr-cmd-utils by tblsoft.
the class JsonReader method read.
public void read() {
try {
ScriptEngineManager mgr = new ScriptEngineManager();
engine = mgr.getEngineByName("JavaScript");
String internalFilename = getProperty("filename", null);
filename = IOUtils.getAbsoluteFile(getBaseDir(), internalFilename);
String internalJavaScriptFilename = getProperty("javaScriptFilename", null);
javaScriptFilename = IOUtils.getAbsoluteFile(getBaseDir(), internalJavaScriptFilename);
rootPath = getProperty("rootPath", "$");
script = FileUtils.readFileToString(new File(javaScriptFilename));
cx = Context.enter();
JsonSurfer surfer = JsonSurferGson.INSTANCE;
java.io.Reader sample = new FileReader(filename);
surfer.configBuilder().bind(rootPath, new JsonPathListener() {
public void onValue(Object value, ParsingContext context) {
Scriptable scope = cx.initStandardObjects();
List<Document> output = new ArrayList<Document>();
ScriptableObject.putProperty(scope, "documentBuilder", Context.javaToJS(new DocumentBuilder(), scope));
ScriptableObject.putProperty(scope, "output", Context.javaToJS(output, scope));
String exec = "var input = " + value.toString() + ";" + script;
cx.evaluateString(scope, exec, filename, 1, null);
for (Document out : output) {
executer.document(out);
}
}
}).buildAndSurf(sample);
sample.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations