diff options
| author | kumar <kumar.damani@mail.utoronto.ca> | 2016-07-24 06:00:18 +0000 |
|---|---|---|
| committer | kumar <kumar.damani@mail.utoronto.ca> | 2016-07-24 06:00:18 +0000 |
| commit | a4cadfb98def3ac6aaee3bb5a166fb0fd7072211 (patch) | |
| tree | 2ff1a14a065cfa9c4486e28922f6f357b32b4e63 /node_simple.js | |
| parent | 513312a00975a3fa0848736829e00d46825e853f (diff) | |
added user search
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/node_simple.js b/node_simple.js index 74a28db..05f04b1 100644 --- a/node_simple.js +++ b/node_simple.js @@ -15,6 +15,7 @@ * 10. comment_history ? DONE * 11. solutions_history ? DONE * 12. voting for solutions ? DONE + * 23. A search users function ? DONE * * */ @@ -98,6 +99,35 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/ //****************************FUNCTIONS************************************************| +exports.search_users = function ( token, callback ) { + + mongoFactory.getConnection(uri).then(function (db) { + var users = db.collection('users'); + users.createIndex( // make the following fields searchable + { + "user_name":"text", + "f_name":"text", + "l_name":"text" + }); + users.find( + { $text: { $search: token } }, + { score: { $meta: "textScore" } } + ).sort( { score: { $meta:"textScore" } } ).toArray(function (err, docs) { + if (err) callback(false, "Error: some error while searhing"); + else { + // console.log(docs); + callback(true, docs); + } + }); + + db.close(); + + }).catch(function (err) { + console.error(err); + }); +}; + + exports.followExam = function (user_name, exam_id, callback) { exports.retrieveFollows(user_name, function (bool, result) { |
