I'm trying to integrate Solr into a Node/Express app and while I am using this Node package for the Solr integration. I am able to properly query the index, but following the instructions on the package's GitHub, I am unable to add documents to the index. I keep getting this error:
[SyntaxError: Unexpected token <]
On the Solr console, the error is a little more detailed:
SEVERE: Error processing "legacy" update command:com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '[' (code 91) in prolog; expected '<'
Here is a small test app I'm using to try and get this working:
// set variables for environment
var express = require('express');
var path = require('path');
var solr = require('solr-client');
// Create the Express app
var app = express();
module.exports = app;
// Initialize the Vash view engine
app.set("views", path.join( __dirname, "/views") );
app.set("view engine", "vash");
// set routes
app.get('/', function(req, res) {
// Create a client
var client = solr.createClient();
var query = 'q=fencing';
client.get('select', query, function(err, obj) {
if (err) {
console.log(err);
} else {
console.log(obj);
}
});
// Switch on "auto commit", by default `client.autoCommit = false`
client.autoCommit = true;
var docs = [];
for(var i = 0; i <= 10 ; i++){
var doc = {
id : 12345 + i,
title_t : "Title "+ i,
description_t : "Text"+ i + "Alice"
};
docs.push(doc);
}
// Add documents
client.add(docs,function(err,obj){
if(err){
console.log(err);
}else{
console.log(obj);
}
});
res.render('index');
});
// Set server port
app.listen(4000);
console.log('server is running on localhost:4000');
The specific part that doesn't work is where I attempt to add a document to the index here:
// Add documents
client.add(docs,function(err,obj){
if(err){
console.log(err);
}else{
console.log(obj);
}
});
My hunch is that this has something to do with receiving JSON when it's expecting XML, but I cannot for the life of me figure out how to either send XML or to enable Solr to accept JSON. Any advice?