Browse Source

Use clean.layers to determine types

This allows removing the types middleware and simplifies some code.
pull/407/head
Julian Simioni 9 years ago
parent
commit
79883594b8
  1. 10
      controller/search.js
  2. 18
      middleware/_types.js
  3. 4
      routes/v1.js

10
controller/search.js

@ -11,7 +11,6 @@ function setup( backend, query ){
// do not run controller when a request
// validation error has occurred.
if( req.errors && req.errors.length ){
delete req.clean.type; //to declutter output
return next();
}
@ -25,12 +24,9 @@ function setup( backend, query ){
body: query( req.clean )
};
// set the Elasticsearch types to filter by,
// and remove the property from clean so the API
// response output is cleaner
if( req.clean.hasOwnProperty('type') ){
cmd.type = req.clean.type;
delete req.clean.type;
// use layers field for filtering by type
if( req.clean.hasOwnProperty('layers') ){
cmd.type = req.clean.layers;
}
logger.debug( '[ES req]', JSON.stringify(cmd) );

18
middleware/_types.js

@ -1,18 +0,0 @@
/**
* Take the layers specified by the layers parameter and use them to set the
* list of Elasticsearch types to filter.
*
* This has to be done outside the layers sanitizer since it doesn't know that
* the layers property is eventualy used to choose the _type.
*/
function middleware(req, res, next) {
req.clean = req.clean || {};
if (req.clean.hasOwnProperty('layers')) {
req.clean.type = req.clean.layers;
}
next();
}
module.exports = middleware;

4
routes/v1.js

@ -12,7 +12,6 @@ var sanitisers = {
/** ----------------------- middleware ------------------------ **/
var middleware = {
types: require('../middleware/_types'),
calcSize: require('../middleware/sizeCalculator')
};
@ -59,7 +58,6 @@ function addRoutes(app, peliasConfig) {
]),
search: createRouter([
sanitisers.search.middleware,
middleware.types,
middleware.calcSize(),
controllers.search(),
postProc.distances('focus.point.'),
@ -72,7 +70,6 @@ function addRoutes(app, peliasConfig) {
]),
autocomplete: createRouter([
sanitisers.autocomplete.middleware,
middleware.types,
controllers.search(null, require('../query/autocomplete')),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
@ -84,7 +81,6 @@ function addRoutes(app, peliasConfig) {
]),
reverse: createRouter([
sanitisers.reverse.middleware,
middleware.types,
middleware.calcSize(),
controllers.search(undefined, reverseQuery),
postProc.distances('point.'),

Loading…
Cancel
Save