|
|
@ -6,19 +6,21 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), |
|
|
|
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; |
|
|
|
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; |
|
|
|
var logger = require('pelias-logger').get('api'); |
|
|
|
var logger = require('pelias-logger').get('api'); |
|
|
|
var logging = require( '../helper/logging' ); |
|
|
|
var logging = require( '../helper/logging' ); |
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
|
|
// middleware
|
|
|
|
// middleware
|
|
|
|
module.exports.middleware = function( req, res, next ){ |
|
|
|
module.exports.middleware = function( req, res, next ){ |
|
|
|
// if res.data already has results then don't call the _text_autocomplete sanitizer
|
|
|
|
// if res.data already has results then don't call the _text_autocomplete sanitizer
|
|
|
|
// this has been put into place for when the libpostal integration way of querying
|
|
|
|
// this has been put into place for when the libpostal integration way of querying
|
|
|
|
// ES doesn't return anything and we want to fallback to the old logic
|
|
|
|
// ES doesn't return anything and we want to fallback to the old logic
|
|
|
|
if (res && res.hasOwnProperty('data') && res.data.length > 0) { |
|
|
|
if (_.get(res, 'data', []).length > 0) { |
|
|
|
return next(); |
|
|
|
return next(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// log the query that caused a fallback since libpostal+new-queries didn't return anything
|
|
|
|
// log the query that caused a fallback since libpostal+new-queries didn't return anything
|
|
|
|
if (req.path === '/v1/search') { |
|
|
|
if (req.path === '/v1/search') { |
|
|
|
var queryText = logging.isDNT(req) ? '[text removed]' : req.clean.text; |
|
|
|
const queryText = logging.isDNT(req) ? '[text removed]' : req.clean.text; |
|
|
|
|
|
|
|
logger.info(`fallback queryText: ${queryText}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sanitize( req, function( err, clean ){ |
|
|
|
sanitize( req, function( err, clean ){ |
|
|
|