Browse Source

added condition to exit early if there are already results in `res`

in order to accommodate falling back to the existing search strategy, the search controller must exit early if the `res.data` already exists.
pull/666/head
Stephen Hess 8 years ago
parent
commit
4952a0ed2b
  1. 7
      controller/search.js
  2. 22
      test/unit/controller/search.js

7
controller/search.js

@ -17,6 +17,13 @@ function setup( config, backend, query ){
return next();
}
// do not run controller if there are already results
// this was added during libpostal integration. if the libpostal parse/query
// doesn't return anything then fallback to old search-engine-y behavior
if (res && res.hasOwnProperty('data')) {
return next();
}
var cleanOutput = _.cloneDeep(req.clean);
if (logging.isDNT(req)) {
cleanOutput = logging.removeFields(cleanOutput);

22
test/unit/controller/search.js

@ -171,6 +171,28 @@ module.exports.tests.timeout = function(test, common) {
});
};
module.exports.tests.existing_results = function(test, common) {
test('res with existing data should not call backend', function(t) {
var backend = function() {
throw new Error('backend should not have been called');
};
var controller = setup( fakeDefaultConfig, backend, mockQuery() );
var req = { };
// the existence of `data` means that there are already results so
// don't call the backend/query
var res = { data: [] };
var next = function() {
t.deepEqual(res, {data: []});
t.end();
};
controller(req, res, next);
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save