diff --git a/limestone.js b/limestone.js index 9bf916d..4626b11 100644 --- a/limestone.js +++ b/limestone.js @@ -559,7 +559,9 @@ exports.SphinxClient = function() { var data = this.read(); // Got response! response_output.append(data); - response_output.runCallbackIfDone(_queue[0]['search_command']); + if (_queue.length > 0) { + response_output.runCallbackIfDone(_queue[0]['search_command']); + } } function initResponseOutput(query_callback) { @@ -584,14 +586,15 @@ exports.SphinxClient = function() { } }, append : function(data) { - //this.data.write(data.toString('utf-8'), 'utf-8'); - // console.log('Appending ' + data.length + ' bytes'); - var new_buffer = new Buffer(this.data.length + data.length); - this.data.copy(new_buffer, 0, 0); - data.copy(new_buffer, this.data.length, 0); - this.data = new_buffer; - // console.log('Data length after appending: ' + this.data.length); - this.parseHeader(); + if (data) { + //this.data.write(data.toString('utf-8'), 'utf-8'); + var new_buffer = new Buffer(this.data.length + data.length); + this.data.copy(new_buffer, 0, 0); + data.copy(new_buffer, this.data.length, 0); + this.data = new_buffer; + // console.log('Data length after appending: ' + this.data.length); + this.parseHeader(); + } }, done : function() { // console.log('Length: ' + this.data.length + ' / ' + this.length); diff --git a/purels.js b/purels.js index 8e46ef0..e1ae5c1 100644 --- a/purels.js +++ b/purels.js @@ -1,13 +1,17 @@ var limestone = require("./limestone").SphinxClient(); +var testString = 'test'; + // 9312 is standard Sphinx port limestone.connect(9312, function(err) { if (err) { - console.log('Connection error: ' + err); + console.log('Connection error: ' + err.message); + console.log('Maybe Sphinx is not started or uses port different than 9312'); + process.exit(); } console.log('Connected, sending query'); - limestone.query({'query':'test', maxmatches:1, 'fieldweights': {'name': 80, 'body': 30}}, function(err, answer) { + limestone.query({'query':testString, maxmatches:1, 'fieldweights': {'name': 80, 'body': 30}}, function(err, answer) { limestone.disconnect(); - console.log("Extended search for 'test' yielded " + answer.match_count + " results: " + JSON.stringify(answer)); + console.log("Extended search for '" + testString + "' yielded " + answer.match_count + " results: " + JSON.stringify(answer)); }); -}); +}); \ No newline at end of file