Skip to content

Commit

Permalink
Fixing #33
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokikaze committed Feb 19, 2014
1 parent 05c60c1 commit 798484e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
21 changes: 12 additions & 9 deletions limestone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions purels.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
});

0 comments on commit 798484e

Please sign in to comment.