diff --git a/controller/suggest.js b/controller/suggest.js index b64a407e..1fc61bee 100644 --- a/controller/suggest.js +++ b/controller/suggest.js @@ -40,6 +40,12 @@ function setup( backend, query ){ }); }; + var sort_by_score = function(combined) { + return combined.sort(function(a,b) { + return b.score - a.score; + }); + }; + var respond = function(data) { // convert docs to geojson @@ -96,6 +102,15 @@ function setup( backend, query ){ } } + // fuzzy + async_query.fuzzy = function(callback){ + cmd.body = query( req.clean, 3 ); + cmd.body.pelias.completion.fuzzy = { + 'fuzziness': 'AUTO' + }; + query_backend(cmd, callback); + }; + async.parallel(async_query, function(err, results) { // results is equal to: {a: docs, b: docs, c: docs} var splice_length = parseInt((SIZE / Object.keys(results).length), 10); @@ -103,7 +118,7 @@ function setup( backend, query ){ var combined = []; results_keys.forEach(function(key){ - combined = combined.concat(results[key].splice(0,splice_length)); + combined = combined.concat(sort_by_score(results[key]).splice(0,splice_length)); }); combined = dedup(combined); diff --git a/query/suggest.js b/query/suggest.js index 75cf1289..29f2f0b3 100644 --- a/query/suggest.js +++ b/query/suggest.js @@ -25,9 +25,6 @@ function generate( params, precision ){ 'completion' : { 'size' : params.size, 'field' : 'suggest', - 'fuzzy' : { - 'fuzziness' : 'AUTO' - }, 'context': { 'dataset': params.layers, 'location': {