Browse Source

cant make all suggest queries fuzzy. so, moving it back into the controller. Adding sort_by_score

fuzzy
Harish Krishna 10 years ago
parent
commit
04c81f761b
  1. 17
      controller/suggest.js
  2. 3
      query/suggest.js

17
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);

3
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': {

Loading…
Cancel
Save