Skip to content

Instantly share code, notes, and snippets.

@nootanghimire
Created October 21, 2015 19:54
Show Gist options
  • Save nootanghimire/363fce60cc5c87c31e5c to your computer and use it in GitHub Desktop.
Save nootanghimire/363fce60cc5c87c31e5c to your computer and use it in GitHub Desktop.
exports.findResultsByFreeText = function(req, res, next, freeText) {
//TODO: Check if request contains facet params, and filter accordingly
req.results = []; //Array
getListOfTeams(req.user.username).then(function(results) {
promise_map(function(result){
//console.log("a");
elasticsearch_client.search({
index: result.teamUnique + "_team",
type: result.username,
body: {
query: {
match: {
name: freeText
}
}
}
}).then(function(resp) {
req.results.push(resp);
}, function(err) {
console.log("ErrorA:: " + err);
});
}, Promise.all(results));
next();
}, function(err) {
console.log("ErrorB:: " + err);
});
}
var getListOfTeams = function(username) {
return new Promise(function(resolve, reject){
if(!username){
reject({"ErrorType":"UserNotFound", "Remarks":""});
}
TeamsToUsers.find({
username:username
}, function(err, results){
if(err){
reject({"ErrorType":"ErrorInQuery", "Remarks":err});
}
else {
resolve(results);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment