Browse Source

added category sanitiser to /search and updated search query to add the should match clause

got tests to pass: by not setting an empty array as categories

attempts to fix https://github.com/pelias/api/issues/128
category
Harish Krishna 9 years ago
parent
commit
506dc6d9da
  1. 9
      query/search.js
  2. 4
      sanitiser/_categories.js
  3. 3
      sanitiser/search.js
  4. 3
      test/unit/sanitiser/reverse.js

9
query/search.js

@ -44,6 +44,15 @@ function generate( params ){
});
}
// add category mapping
if (params.categories) {
query.query.filtered.query.bool.should.push({
'match': {
'category': params.categories
}
});
}
// add phrase matching query
// note: this is required for shingle/phrase matching
query.query.filtered.query.bool.should.push({

4
sanitiser/_categories.js

@ -27,6 +27,10 @@ function sanitize( req ){
});
}
if (clean.categories.length === 0) {
delete clean.categories;
}
// pass validated params to next middleware
req.clean = clean;

3
sanitiser/search.js

@ -5,7 +5,8 @@ var _sanitize = require('../sanitiser/_sanitize'),
size: require('../sanitiser/_size'),
layers: require('../sanitiser/_layers'),
details: require('../sanitiser/_details'),
latlonzoom: require('../sanitiser/_geo')
latlonzoom: require('../sanitiser/_geo'),
categories: require('../sanitiser/_categories')
};
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };

3
test/unit/sanitiser/reverse.js

@ -9,8 +9,7 @@ var suggest = require('../../../sanitiser/reverse'),
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
lon: 0,
size: 10,
details: true,
categories: []
details: true
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };

Loading…
Cancel
Save