Skip to content

Commit

Permalink
Added simple query syntax to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokikaze committed Feb 20, 2014
1 parent 182e0ab commit 5910c01
Showing 1 changed file with 60 additions and 50 deletions.
110 changes: 60 additions & 50 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ Usage:
console.log('Connection error: ' + err.message);
process.exit();
}
console.log('Connected, sending query');
limestone.query(
console.log('Connected, sending queries');
limestone.query('test', function(err, answer) { // Simple query
console.log('Simple query returned ' + answer.match_count + 'results');
});
limestone.query( // Query with options
{'query':'test', maxmatches:1},
function(err, answer) {
limestone.disconnect();
Expand All @@ -24,59 +29,64 @@ Usage:
To Use Build_Excerpts:

limestone.connect(9312, // port
function(err) { //callback
if (err) {
console.log('Connection error: ' + err);
}
console.log('Connected Build Excerpts');
limestone.build_excerpts(
['this is my teste text to be highlighted',
'this is another test text to be highlighted'], // docs
'questions_1',
'test text',
{},
function(err, answer) {
limestone.disconnect();
console.log(JSON.stringify(answer));
}
);
});
function(err) { //callback
if (err) {
console.log('Connection error: ' + err);
}
console.log('Connected Build Excerpts');
limestone.build_excerpts(
[
'this is my teste text to be highlighted',
'this is another test text to be highlighted'
], // docs
'questions_1',
'test text',
{},
function(err, answer) {
limestone.disconnect();
console.log(JSON.stringify(answer));
}
);
}
);

Bonus: persistent connection:
You can ask sphinx to open a persistent connection. You can then make several request through the same connection

limestone.connect(9312, // port
true, // persistent (optional)
function(err) { // callback
if (err){
console.log('Connection error: ' + err);
}
console.log('Connected Search');
console.log('sending query');
limestone.query(
{'query':'test', // query obj with sphinx opts
maxmatches:1,
indexes:'questions_1,products_3'},
function(err, answer){ // callback
console.log('Extended search yielded ' +
answer.match_count + " results\n" +
JSON.stringify(answer));
limestone.build_excerpts(
['this is my teste text to be highlighted',
'this is another test text to be highlighted'], // docs
'questions_1', // index
'test text', // words
{},
function(err, answer){
limestone.disconnect();
console.log(JSON.stringify(answer));
}
);
}
);
});
true, // persistent (optional)
function(err) { // callback
if (err){
console.log('Connection error: ' + err);
}
console.log('Connected Search');
console.log('sending query');
limestone.query({
'query' : 'test', // query object with sphinx options
'maxmatches' : 1,
'indexes':'questions_1,products_3'},
function(err, answer){ // callback
console.log('Extended search yielded ' +
answer.match_count + " results\n" +
JSON.stringify(answer));
limestone.build_excerpts([
'this is my test text to be highlighted',
'this is another test text to be highlighted'
], // docs
'questions_1', // index
'test text', // words
{},
function(err, answer){
limestone.disconnect();
console.log(JSON.stringify(answer));
}
);
}
);
}
);

Limestone is queueing now:
You can safely call limestone.query or limestone.build_excerpts methods outside the scope of the callback functions, provided the connection is made persistent. Limestone will enqueue the sphinx commands and run them sequentially.
Expand Down

0 comments on commit 5910c01

Please sign in to comment.