Permalink
Browse files

More correct callback-nested example in README

Closes #16
  • Loading branch information...
1 parent 349b393 commit a44831b965ff5b54abf1f3f6135b0f29374309b7 @gsf committed Mar 6, 2012
Showing with 24 additions and 21 deletions.
  1. +24 −21 README
View
45 README
@@ -22,27 +22,30 @@ See tests for usage. Here's a quick example:
title_t: 'Far boo',
text_t: 'Wuzz fizz drizzle'
};
- var callback = function(err, response) {
- if (err) throw err;
- console.log('Document added');
- };
- client.add(doc1, callback);
- client.add(doc2, callback);
- client.commit();
-
- var query = 'text_t:fizz'
- client.query(query, function(err, response) {
- if (err) throw err;
- var responseObj = JSON.parse(response);
- console.log('A search for "' + query + '" returned ' +
- responseObj.response.numFound + ' documents.');
- console.log('First doc title: ' + responseObj.response.docs[0].title_t);
- console.log('Second doc title: ' + responseObj.response.docs[1].title_t);
- });
- var id;
- client.del(id, query, function(err, response) {
+ client.add(doc1, function(err) {
if (err) throw err;
- console.log('Deleted all docs matching query "' + query + '"');
+ console.log('First document added');
+ client.add(doc2, function(err) {
+ if (err) throw err;
+ console.log('Second document added');
+ client.commit(function(err) {
+ var query = 'text_t:fizz'
+ client.query(query, function(err, response) {
+ if (err) throw err;
+ var responseObj = JSON.parse(response);
+ console.log('A search for "' + query + '" returned ' +
+ responseObj.response.numFound + ' documents.');
+ console.log('First doc title: ' +
+ responseObj.response.docs[0].title_t);
+ console.log('Second doc title: ' +
+ responseObj.response.docs[1].title_t);
+ client.del(null, query, function(err, response) {
+ if (err) throw err;
+ console.log('Deleted all docs matching query "' + query + '"');
+ client.commit()
+ });
+ });
+ });
+ });
});
- client.commit()

0 comments on commit a44831b

Please sign in to comment.