Browse Source

mixing the results so that we always have the limit (10) coming back

msv2
Harish Krishna 10 years ago
parent
commit
da4fa58e0e
  1. 14
      controller/suggest.js

14
controller/suggest.js

@ -94,14 +94,20 @@ function setup( backend, query ){
} }
async.parallel(async_query, function(err, results) { async.parallel(async_query, function(err, results) {
var splice_length = parseInt((req.clean.size / Object.keys(results).length), 10);
// results is equal to: {a: docs, b: docs, c: docs} // results is equal to: {a: docs, b: docs, c: docs}
var combined = []; var combined = [];
var total_results = 0;
for (keys in results) {
total_results += results[keys].length;
}
for (keys in results) { for (keys in results) {
var results_length= results[keys].length;
var splice_length = parseInt(Math.ceil(results_length*results_length/total_results),10);
combined = combined.concat(results[keys].splice(0,splice_length)); combined = combined.concat(results[keys].splice(0,splice_length));
} }
combined = combined.splice(0, req.clean.size);
combined = dedup(combined); combined = dedup(combined);
respond(combined); respond(combined);
}); });

Loading…
Cancel
Save